如何在使用Facebook iPhone SDK时刷新oauth令牌 [英] how to refresh an oauth token when using the Facebook iPhone SDK

查看:102
本文介绍了如何在使用Facebook iPhone SDK时刷新oauth令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用中使用Facebook SDK for iOS: http://github.com / facebook / facebook-ios-sdk

I'm using the Facebook SDK for iOS in my app: http://github.com/facebook/facebook-ios-sdk

oAuth令牌在约2小时后到期。如何在不必再次调用[Facebook授权...]方法的情况下刷新oAuth令牌 - 如果用户之前已登录,则会短暂显示一个空的Facebook对话框?我想要避免的是要求用户每次使用应用程序时重新登录FB - 比如说,每天。

The oAuth token expires after about 2 hours. How can I "refresh" the oAuth token without having to call the [Facebook authorize...] method again - which shows an empty Facebook dialog briefly if the user had previously logged in? What I want to avoid is requiring the user to re-login to FB each time they use the app - say, day to day.

我已经在保存/恢复oAuth应用程序退出/启动时的令牌。我可以使用[Facebook isSessionValid]检查令牌是否有效,或者检查令牌上的过期时间。但是如果令牌已经过期该怎么办?我已经读过可以刷新令牌,但我不明白这是怎么做的。

I am already saving / restoring oAuth tokens when the app exits / starts. And I can check to see if the token is valid using [Facebook isSessionValid], or by checking the expire time on the token. But what to do if the token has expired? I've read that it is possible to "refresh" the token, but I don't understand how this is done.

我不想请求offline_access 许可,这将给我一个永远的标记。

I don't want to request "offline_access" permission, which would give me a "forever" token.

帮助!?

推荐答案

Facebook的OAuth实现不支持令牌刷新。

Facebook's implementation of OAuth doesn't support token refresh.

Facebook中有两种类型的access_tokens。短期令牌,默认情况下给出,如果您请求offline_access,则会给出长期令牌。如果支持刷新令牌,则与为所有应用程序提供offline_access令牌相同。

You have 2 types of access_tokens in Facebook. Short term token, which is given by default and a long term token which is given if you request offline_access. If refresh token were supported, it was the same as giving a offline_access token for all apps.

只要用户在您的网络控件上有一个有效的Facebook会话,您只需访问 https://www.facebook.com/ dialog / oauth?client_id = YOUR_APP_ID& redirect_uri = http://www.facebook.com/connect/login_success.html& response_type = token 或者可能是一些iOS SDK命令也是如此(从未使用过它,所以我不能告诉)。此类请求不会要求用户再次登录,而是使用在首次登录时创建的上一个会话。

As long as the user has an active facebook session on your web control, you can request a new access_token just by accessing https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri=http://www.facebook.com/connect/login_success.html&response_type=token or probably some iOS SDK command that does the same (never worked with it so I can't tell). This kind of request will not ask the user to login again, but will use the previous session that was created during the first login.

这篇关于如何在使用Facebook iPhone SDK时刷新oauth令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆