ios - youtube upload error: GTLJSONRPCErrorDomain Code=401 -


when try login youtube , upload video, gets uploaded without issue. if upload video after 2-3 hours, error saying,

error: error domain=com.google.gtljsonrpcerrordomain code=401 "the operation couldn’t completed. (invalid credentials)" userinfo=0x14585d90 {error=invalid credentials, gtlstructurederror=gtlerrorobject 0x14d85ba0: {message:"invalid credentials" code:401 data:[1]}, nslocalizedfailurereason=(invalid credentials)} 

here code youtube login,

gidsignin *googlesignin = [gdsharedinstance googlesdkapplicationsharedinstance];     googlesignin.delegate = self;     googlesignin.scopes  = [nsarray arraywithobject:@"https://www.googleapis.com/auth/youtube"];     [googlesignin signin]; 

signin delegate

  - (void)signin:(gidsignin *)signin didsigninforuser:(gidgoogleuser *)user witherror:(nserror *)error     {  // auth converted use uploading video      gtmoauth2authentication *youtubeauth = [[gtmoauth2authentication alloc] init];          youtubeauth.clientid = kclientid;         youtubeauth.clientsecret = @"xxx";         youtubeauth.useremail = googleuser.profile.email;         youtubeauth.userid = googleuser.userid;         youtubeauth.accesstoken = googleuser.authentication.accesstoken;         youtubeauth.refreshtoken = googleuser.authentication.refreshtoken;         youtubeauth.expirationdate = googleuser.authentication.accesstokenexpirationdate;         self.youtubeservice.authorizer = youtubeauth;     } 

upload code,

nsfilehandle *filehandle = [nsfilehandle filehandleforreadingfromurl:[nsurl urlwithstring:path] error:&error];     if (filehandle) {         nsstring *mimetype = [self mimetypeforfilename:filename                                        defaultmimetype:@"video/mov"];         gtluploadparameters *uploadparameters =         [gtluploadparameters uploadparameterswithfilehandle:filehandle                                                    mimetype:mimetype];         uploadparameters.uploadlocationurl = locationurl;          gtlqueryyoutube *query = [gtlqueryyoutube queryforvideosinsertwithobject:video                                                                             part:@"snippet,status,recordingdetails"                                                                 uploadparameters:uploadparameters];             gtlserviceyoutube *service = self.youtubeservice;              self.uploadfileticket = [service executequery:query                                     completionhandler:^(gtlserviceticket *ticket,                                                         gtlyoutubevideo *uploadedvideo,                                                         nserror *error)                                      {                                         // here 401 error                                     }];       } 

the problem gtlserviceyoutube. gidsignin seems handle refresh tokens, user logged in after first login. gtloauth2authentication works on first login , broken after 1 hour.

the token needs refreshed.

use piece of code :-

- (void)applicationwillenterforeground:(uiapplication *)application {   [[gidsignin sharedinstance] signinsilently]  } 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -