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_
Ok it seems that it's the facebook iOS SDK which is buggy.
Using the token stored in the user defaults, i can perform a post on my wall using curl :
curl -F 'access_token=br69pK_lh0Xbj....plDRUdG97a55KIHzlaiw' \
-F 'message=TEST API.' \
https://graph.facebook.com/ME/feed
So i just perform a HTTPS POST, so using ASIHTTPRequest this code works like a charm :
NSURL* faceboobUrl = [NSURL URLWithString:@"https://graph.facebook.com/ME/feed"];
self.request = [ASIFormDataRequest requestWithURL:faceboobUrl];
[request setRequestMethod:@"POST"];
[request setPostValue:token forKey:@"access_token"];
[request setPostValue:msg forKey:@"message"];
[request setDelegate:self];
[request setTimeOutSeconds:TIMEOUT];
[request startAsynchronous];
No thanks facebook ;)
Vincent
Make sure to call :
[[NSUserDefaults standardUserDefaults] synchronize];
This will "save" your preferences to disk/flash.
Also do an NSLog on the token before you save it to make sure it's not nil.
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:
[[NSUserDefaults standardUserDefaults] setObject:_facebook.accessToken forKey:@"fb_access_token"];
[[NSUserDefaults standardUserDefaults] setObject:_facebook.expirationDate forKey:@"fb_exp_date"];
Retrieving is the same, just set the _facebook.expirationDate
.