Tumblr Callback function in ios -


i beginner in ios. have started integration of tumblr app in ios. need stuck in implementation. want login in tumblr , viewcontroller. this, following this link.

i have implemented code , getting webview of tumblr. but, facing issue in returning view controller , getting logged in id i.e. not considering clientid & secret have mentioned.

here code.

-(void)viewdidload  {   [super viewdidload];   clientid = @"pld4s********************************";   secret = @"aljie8x********************************";   redirect = @"tumblr://authorized";    [self connecttumblr]; } - (void)viewwillappear:(bool)animated  {   webview.delegate = self; } - (void)connecttumblr  {   consumer = [[oaconsumer alloc]initwithkey:clientid secret:secret];    nsurl* requesttokenurl = [nsurl urlwithstring:@"https://www.tumblr.com/oauth/request_token"];    oamutableurlrequest* requesttokenrequest = [[oamutableurlrequest alloc] initwithurl:requesttokenurl consumer:consumer token:nil realm:nil signatureprovider:nil] ;    oarequestparameter* callbackparam = [[oarequestparameter alloc] initwithname:@"oauth_callback" value:redirect] ;    [requesttokenrequest sethttpmethod:@"post"];    [requesttokenrequest setparameters:[nsarray arraywithobject:callbackparam]];    oadatafetcher* datafetcher = [[oadatafetcher alloc] init] ;    [datafetcher fetchdatawithrequest:requesttokenrequest delegate:self didfinishselector:@selector(didreceiverequesttoken:data:)                                     didfailselector:@selector(didfailoauth:error:)];    }   - (void)didreceiverequesttoken:(oaserviceticket*)ticket data:(nsdata*)data {   nsstring* httpbody = [[nsstring alloc] initwithdata:data encoding:nsutf8stringencoding];    requesttoken = [[oatoken alloc] initwithhttpresponsebody:httpbody];    nsurl* authorizeurl = [nsurl urlwithstring:@"https://www.tumblr.com/oauth/authorize"];    oamutableurlrequest* authorizerequest = [[oamutableurlrequest alloc] initwithurl:authorizeurl consumer:nil token:nil realm:nil                                          signatureprovider:nil];    nsstring* oauthtoken = requesttoken.key;    oarequestparameter* oauthtokenparam = [[oarequestparameter alloc] initwithname:@"oauth_token" value:oauthtoken] ;    [authorizerequest setparameters:[nsarray arraywithobject:oauthtokenparam]];    [webview loadrequest:authorizerequest]; }  - (void)didfailoauth:(oaserviceticket*)ticket error:(nserror*)error {   nslog(@"oauth fail"); }  - (bool)webview:(uiwebview*)webview shouldstartloadwithrequest:(nsurlrequest*)request navigationtype:(uiwebviewnavigationtype)navigationtype  {   if ([[[request url] scheme] isequal:@"tumblr"] )   {     // extract oauth_verifier url query     nsstring* verifier = nil;      nsarray* urlparams = [[[request url] query] componentsseparatedbystring:@"&"];      (nsstring* param in urlparams)      {         nsarray* keyvalue = [param componentsseparatedbystring:@"="];          nsstring* key = [keyvalue objectatindex:0];          if ([key isequal:@"oauth_verifier"]) {              verifier = [keyvalue objectatindex:1];             break;         }     }     if (verifier) {          nsurl* accesstokenurl = [nsurl urlwithstring:@"https://www.tumblr.com/oauth/access_token"];          oamutableurlrequest* accesstokenrequest = [[oamutableurlrequest alloc] initwithurl:accesstokenurl consumer:consumer token:requesttoken realm:nil signatureprovider:nil];          oarequestparameter* verifierparam = [[oarequestparameter alloc] initwithname:@"oauth_verifier" value:verifier];          [accesstokenrequest sethttpmethod:@"post"];          [accesstokenrequest setparameters:[nsarray arraywithobject:verifierparam]];          oadatafetcher* datafetcher = [[oadatafetcher alloc] init];          [datafetcher fetchdatawithrequest:accesstokenrequest delegate:self didfinishselector:@selector(didreceiveaccesstoken:data:)          didfailselector:@selector(didfailoauth:error:)];      } else {         // error!     }                                                     [webview removefromsuperview];     return no;    }    return yes;   }   - (void)didreceiveaccesstoken:(oaserviceticket*)ticket data:(nsdata*)data    {       nsstring* httpbody = [[nsstring alloc] initwithdata:data encoding:nsutf8stringencoding];       accesstoken = [[oatoken alloc] initwithhttpresponsebody:httpbody];        nsstring *oauthkey = accesstoken.key;    // here access token        nsstring *oauthsecret = accesstoken.secret;  //here  secret token        uialertview *alertview = [[uialertview alloc]initwithtitle:@"tumblr token" message:oauthsecret delegate:nil cancelbuttontitle:@"ok"                                             otherbuttontitles:nil];       [alertview show];   } 

clientid & secret , haveenter code here taken tumblr after registration.

thank you.

i suggest put breakpoints on several place & check flow of login , give error message

  1. shouldstartloadwithrequest
  2. if (verifier) {
  3. [datafetcher fetchdatawithrequest:accesstokenrequest delegate:self didfinishselector:@selector(didreceiveaccesstoken:data:) didfailselector:@selector(didfailoauth:error:)];

  4. didreceiveaccesstoken

  5. didfailoauth

i think miss error method of. here it.

- (void)didfailodatah:(oaserviceticket*)ticket error:(nserror*)error {     // error! } 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -