如何在后台刷新长期存在的 Facebook 访问 token ?来自 Facebook documentation
Even the long-lived access token will eventually expire. At any point, you can generate a new long-lived token by sending the person back to the login flow used by your web app - note that the person will not actually need to login again, they have already authorized your app, so they will immediately redirect back to your app from the login flow with a refreshed token - how this appears to the person will vary based on the type of login flow that you are using, for example if you are using the JavaScript SDK, this will take place in the background, if you are using a server-side flow, the browser will quickly redirect to the Login Dialog and then automatically and immediately back to your app again.
我想要协调的是,为了获得新的访问 token ,您需要让用户登录。为了登录,您必须调用FB.login()
。根据documentation ,用户应该单击按钮才能登录。
As noted in the reference docs for this function, it results in a pop-up window showing the Login dialog, and therefore should only be invoked as a result of someone clicking an HTML button (so that the pop-up isn't blocked by browsers).
如何使用 facebook javascript SDK 在后台刷新长期访问 token ?
请您参考如下方法:
只有当用户访问您的网站时,您才能刷新用户 token :使用FB.getLoginStatus为了那个原因。您不需要使用 FB.login - 它只会在用户交互(点击事件)上起作用,因为如果您尝试自动调用它,浏览器通常会阻止弹出窗口。