Storing facebook token for offline access

前端 未结 3 971
礼貌的吻别
礼貌的吻别 2021-01-03 16:54

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_

相关标签:
3条回答
  • 2021-01-03 17:23

    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

    0 讨论(0)
  • 2021-01-03 17:29

    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.

    0 讨论(0)
  • 2021-01-03 17:32

    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.

    0 讨论(0)
提交回复
热议问题