ios - Import user read and want to read book using facebook sdk -
i'm working on book related app. i'm fetching user likes books using me/books , it's not required permissions , working fine.
now want user finished , want read books
me/books - no permission required
me/books.reads , me/books.wants_to_read required user_actions.books permission.
when try login permission "user_actions.books". i'm getting following error.
error : error domain=com.facebook.sdk code=2 "the operation couldn’t completed. (com.facebook.sdk error 2.)" userinfo=0x10d055b80 {com.facebook.sdk:errorloginfailedreason=com.facebook.sdk:systemlogincancelled, com.facebook.sdk:errorinnererrorkey=error domain=com.apple.accounts code=7 "the operation couldn’t completed. (com.apple.accounts error 7.)", com.facebook.sdk:errorsessionkey=, expirationdate: (null), refreshdate: (null), attemptedrefreshdate: 0001-12-30 00:00:00 +0000, permissions:(null)>}
code :
-(void)importbooksfromfacebook{ // if session state of 2 "open" states when button clicked if (fbsession.activesession.state == fbsessionstateopen || fbsession.activesession.state == fbsessionstateopentokenextended) { // close session , remove access token cache // session state handler (in app delegate) called automatically [fbsession.activesession closeandcleartokeninformation]; // if session state not of 2 "open" states when button clicked } else { // open session showing user login ui // must ask public_profile permissions when opening session [fbsession openactivesessionwithreadpermissions:@[@"user_actions.books"] allowloginui:yes completionhandler: ^(fbsession *session, fbsessionstate state, nserror *error) { // if session opened if (!error && state == fbsessionstateopen){ nslog(@"session opened"); // show user logged-in ui // successful login import book using access token return; } if (state == fbsessionstateclosed || state == fbsessionstateclosedloginfailed){ // if session closed nslog(@"session closed"); // show user logged-out ui [self userloggedout]; } // handle errors if (error){ nslog(@"error"); nsstring *alerttext; nsstring *alerttitle; // if error requires people using app make action outside of app in order recover if ([fberrorutility shouldnotifyuserforerror:error] == yes){ alerttitle = @"something went wrong"; alerttext = [fberrorutility usermessageforerror:error]; [self showmessage:alerttext withtitle:alerttitle]; } else { // if user cancelled login, nothing if ([fberrorutility errorcategoryforerror:error] == fberrorcategoryusercancelled) { nslog(@"user cancelled login"); // handle session closures happen outside of app } else if ([fberrorutility errorcategoryforerror:error] == fberrorcategoryauthenticationreopensession){ alerttitle = @"session error"; alerttext = @"your current session no longer valid. please log in again."; [self showmessage:alerttext withtitle:alerttitle]; // here handle other errors generic error message. // recommend check our handling errors guide more information // https://developers.facebook.com/docs/ios/errors/ } else { //get more error information error nsdictionary *errorinformation = [[[error.userinfo objectforkey:@"com.facebook.sdk:parsedjsonresponsekey"] objectforkey:@"body"] objectforkey:@"error"]; // show user error message alerttitle = @"something went wrong"; alerttext = [nsstring stringwithformat:@"please retry. \n\n if problem persists contact , mention error code: %@", [errorinformation objectforkey:@"message"]]; [self showmessage:alerttext withtitle:alerttitle]; } } // clear token [fbsession.activesession closeandcleartokeninformation]; // show user logged-out ui //[self userloggedout]; } }]; } }
i solved issue below stackoverflow answer :
https://stackoverflow.com/a/14696106/1237937
if ([[fbsession activesession] isopen]) { /* * if current session has no publish permission need reauthorize */ if ([[[fbsession activesession] permissions]indexofobject:@"publish_actions"] == nsnotfound) { [[fbsession activesession] requestnewpublishpermissions:[nsarray arraywithobject:@"publish_actions"] defaultaudience:fbsessiondefaultaudiencefriends completionhandler:^(fbsession *session,nserror *error){ [self postphoto]; }]; }else{ [self publishstory]; } }else{ /* * open new session publish permission */ [fbsession openactivesessionwithpublishpermissions:[nsarray arraywithobject:@"publish_actions"] defaultaudience:fbsessiondefaultaudienceonlyme allowloginui:yes completionhandler:^(fbsession *session, fbsessionstate status, nserror *error) { if (!error && status == fbsessionstateopen) { [self publishstory]; }else{ nslog(@"error"); } }]; }
Comments
Post a Comment