I am looking for a way to save the access token to allow the user to post on facebook without having to log in for each call to the graph API :
I require an offline_access token, i store it in the NSUserDefaults, but when i try to use it again i get a FacebookErrDomain error 10000
Here is what i do :
In the fbDidLogin i get the access_token and save it in the user defaults
- (void)fbDidLogin {
NSString *token = self.facebook.accessToken;
[[NSUserDefaults standardUserDefaults] setObject:token forKey:@"facebookToken"];
}
After that when i run the app again i just get the token from the user defaults, and assign them to the facebook object :
NSString *token = [[NSUserDefaults standardUserDefaults] objectForKey:@"facebookToken"];
[_facebook setAccessToken:token];
But it doesn’t work..
Has anybody any idea what i could be doing wrong ?
Thanks,
Vincent.
EDIT :
If i do a NSlog after [[NSUserDefaults standardUserDefaults] objectForKey:@"facebookToken"]; i can see that the token was saved.
I was having the same problem and I found out that the issue is you are not storing expiration date.
If you do that, it will allow you to relogin in fine.
Sample code:
Retrieving is the same, just set the
_facebook.expirationDate.