存储facebook令牌用于离线访问 [英] Storing facebook token for offline access
问题描述
我正在寻找一种方法来保存访问令牌,以允许用户在Facebook上发布,而无需每次对图形API进行登录:
我需要一个offline_access令牌,我将其存储在NSUserDefaults,但是当我尝试再次使用它,我得到一个FacebookErrDomain错误10000
这是我做的: p>
在fbDidLogin中,我得到access_token并将其保存在用户默认值
- (void)fbDidLogin {
NSString * token = self.facebook.accessToken;
[[NSUserDefaults standardUserDefaults] setObject:token forKey:@facebookToken];
}
之后,当我再次运行应用程序,我只是得到令牌从用户默认值,并将其分配给Facebook对象:
NSString * token = [[NSUserDefaults standardUserDefaults] objectForKey:@ facebookToken];
[_facebook setAccessToken:token];
但它不起作用。
<有人有什么想法我可能做错了吗?
谢谢,
文森特。
编辑:
如果我在之后做一个NSlog [[NSUserDefaults standardUserDefaults] objectForKey:@facebookToken];
我可以看到令牌被保存。 p>
我有同样的问题,我发现问题是你没有存储过期日期。
如果你这样做,它将允许你重新登录。
示例代码:
[[NSUserDefaults standardUserDefaults] setObject:_facebook .accessToken forKey:@fb_access_token];
[[NSUserDefaults standardUserDefaults] setObject:_facebook.expirationDate forKey:@fb_exp_date];
检索是一样的,只需设置 _facebook.expirationDate
。
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:
[[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
.
这篇关于存储facebook令牌用于离线访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!