ios - invalid_token when trying to access Facebook through ACAccount and SLRequest -


I am trying to read a message from a user's Facebook inbox, but I'm killing an error that This entry is from my code:

ACAccountStore * accountStore = [[ACAccountStore alloc] init]; ACAccountType * fbAccountType = [Akountstor account type of Sathakwainttaijaidentifayr: Siakknttaipaidentifayrfesbuk]; NSDictionary * Options = @ {ACFacebookAppIdKey: FacebookAppKey, ACFacebookPermissionsKey: FacebookPermissionsArray}; [AccountStore RequestAccessTo Type: FB Accident Type Option: Option Completion: ^ (BOOL Approved, NSError * Error) {if (error || | granted) {return; } NSArray * accounts = [AccountType with account stair accounts: FBAccountTip]; If (accounts.count == 0) {return; } Ac account * facebookAccount = [accountsObject]; NSURL * inboxURL = [NSURL URLWithString: @ "https://graph.facebook.com/me/inbox"]; NSMutableDictionary * parameter = [[NSMutableDictionary alloc] init]; SLRequest * facebookInfoRequest = [SLRequest requestForServiceType: SLServiceTypeFacebook requestMethod: SLRequestMethodGET URL: inboxURL parameters: Parameter]; [FacebookInfoRequest set account: facebookAccount]; [FacebookInfoRequest performRequestWithHandler: ^ (NSData * responseData, NSHTTPURLResponse * urlResponse, NSError * error) {NSLog (@ "response data:% i, URL response:% @, error:% @", ResponseDataklength, UrlResponse, error); }]; }];

The URL reads the answer to:

  & lt; NSHTTPURL Answer: 0xcb5fa10 & gt; {URL: https://graph.facebook.com/me/inbox?access_token=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX} {Status Code: 400, header { "Access-Control-Allow-Origin" = "*"; "Cash-Control" = "No-Store"; Connection = "keep-alive"; "Content-length" = 194; "Content-type" = "app / jason; charset = utf-8"; Date = "Tuesday, 18 February 2014 15:29:36 GMT"; End = "Saturn, 01 January 2000 00:00:00 GMT"; Pragma = "no-cache"; Error validating "www-Authenticate" = "OAuth \" Facebook Platform \ "\" invalid_token \ "\" access token: session has expired on February 13, 2014 6:17. The current time is February 18, 2014 at 7:29 pm. ""; "X-FB-Debug" = "XXXXXXXXXXXXXXXX / Y + K0w ="; "X-FB-Rev" = XXXXXXXX; }}  

I am sure why this problem has happened, am I doing wrong here?

The Facebook account on the device is out-of-sync with the server and SDK's cache. . Just call to force an update ACAccountStore of method renewCredentialsForAccount

  - (minus) refreshFacebookTokenStatus {ACAccountStore * accountStore; ACAccountType * accountTypeFB; If ((accountStore = [[ACAccountStore alloc] init]) in & amp; & amp; (accountTypeFB = [accountStore accountTypeWithAccountTypeIdentifier: ACAccountTypeIdentifierFacebook])) {NSArray * fbAccounts = [accountStore accountsWithAccountType: accountTypeFB]; ID accounts; If (fbAccounts & amp; [fbAccounts count]> 0 & amp; amp; amp; amp; (accounts = [fbAccounts objectAtIndex: 0])) {[accountStore renewCredentialsForAccount: Account Completion: ^ (ACAccountCredentialRenewResult renewResult, NSError * Error) {if (error) {NSLog (@ "% @", error.localizedDescription); }}]; }}}  

The easiest to do is to call your app every time, but it can not be efficient, so it is better to call when session state changes .

Also make sure there is no sandbox option in your Facebook app setting, if you are trying to log in with the non-app-developer Facebook user.


Comments