php - Facebook 60 天后更新用户 token

标签 php facebook facebook-graph-api

我使用此代码获取 60 天的有效 token

// Set Extended Access Token
$facebook->setExtendedAccessToken();
//get session
$session = $facebook->getAccessToken();

然后我将其存储在数据库中并使用它来发布在用户的墙上(*publish_stream* 权限)。但是有什么办法可以更新 token ,我的用户不太可能在这 60 天内打开应用程序(构建提醒应用程序)。

请提供工作代码或傻瓜操作方法

最佳答案

如果没有用户交互,您无法将 token 延长超过 60 天或续订。

但是,如果您的用户在 60 天内访问您的应用, token 将自动续订,并且将获得另外 60 天的生命周期。

Expiration and Extending Tokens

Facebook's official SDKs manage the lifetime of tokens for you. When using iOS, Android or our JavaScript SDK, the SDK will handle making sure that tokens are refreshed before they expire.

Native mobile applications using Facebook's SDKs will get long-lived access tokens, good for about 60 days. These tokens will be refreshed once per day when the person using your app makes a request to Facebook's servers. If no requests are made, the token will expire after about 60 days and the person will have to go through the login flow again to get a new token.

Access tokens on the web often have a lifetime of about two hours, but will automatically be refreshed when required. If you want to use access tokens for longer-lived web apps, especially server side, you need to generate a long-lived token. A long-lived token generally lasts about 60 days.

另外,在文档中,他们说您不应该依赖这些生命周期,因为用户可以撤销权限、更改密码(更改密码将撤销用户安装的每个应用程序的每个 token )

User access tokens come in two forms: short-lived tokens and long-lived tokens. Short-lived tokens usually have a lifetime of about an hour or two, while long-lived tokens usually have a lifetime of about 60 days. You should not depend on these lifetimes remaining the same - the lifetime may change without warning or expire early.

我引用的所有信息都在这里 https://developers.facebook.com/docs/facebook-login/access-tokens/

关于php - Facebook 60 天后更新用户 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22091114/

相关文章:

swift - swift3 上的 Facebook OpenGraphContent

php - 如何获取 Facebook 的点赞数?

Facebook 应用程序白名单流程

ios - 如何从 FBSession 获取访问 token ?

php - 在 PHP 中运行 Windows Speech SDK 应用程序

php - 在同一页面上显示 mysql 结果

php - Facebook 应用程序开发 - 哪个选项,我可以使用 jQuery 吗?

Python Facebook SDK : 'module' object has no attribute 'GraphAPI'

php - Symfony 2.4 在 TWIG 中渲染 Controller 抛出 "Rendering a fragment can only be done when handling a Request."异常

php - 无法使用 html 格式的 php 邮件从服务器发送邮件