据我所知,这是使用OAuth2 API的新Facebook画布应用程序的基本过程:
问题是访问令牌的过期时间相对较快,需要“刷新”,因此我的问题是:( 1)除了尝试使用令牌之外,如何检测令牌已过期,只需获取一个错误?2)获得新令牌的最佳做法是什么?
目前,我只检测到试图使用访问令牌获取用户信息时出错,然后再次重定向到授权URL --因为他们已经授权了该应用程序一个空白页,并且它们被重定向回我的应用程序回调,在那里我得到了一个新的令牌。太笨重了,真不敢相信这是正确的方法。
发布于 2011-01-07 04:23:26
简单地说,这是没有诀窍的。你已经做对了。
发布于 2012-04-12 22:20:10
最近,facebook对访问令牌进行了一些修改,允许定期刷新令牌。
https://graph.facebook.com/oauth/access_token?
client_id=APP_ID&
client_secret=APP_SECRET&
grant_type=fb_exchange_token&
fb_exchange_token=EXISTING_ACCESS_TOKEN 有关更多详细信息,请参阅此处:https://developers.facebook.com/docs/roadmap/completed-changes/offline-access-removal
发布于 2013-07-31 14:37:48
//you just need more step because the access token you are getting will expire in 1 hour
//you can overcome this in step 5
1-Redirect to (or have user click link to) app's authorization URL
2-User authorizes and is redirected to your callback URL
3-Callback uses "code" parameter to get a access token
4-Access token is used with Graph API to pull or push information
5-exchange short-lived access token you just got with 60 day access token
https://graph.facebook.com/oauth/access_token?client_id=APP_ID&client_secret=APP_SECRET&grant_type=fb_exchange_token&fb_exchange_token=EXISTING_ACCESS_TOKEN
6-after 60 day the user must login again to your app and the steps from 1-5 will be repeated.
--the real problem you will face is how to make the user visit your app page againhttps://stackoverflow.com/questions/4622171
复制相似问题