Facebook 应用程序(非用户)访问令牌过期

发布于 2024-12-28 20:39:47 字数 612 浏览 4 评论 0原文

Facebook APP 访问令牌会过期吗?这些令牌与 USER 令牌不同;它们是这样获取的:

https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id={0}&client_secret={1})

http://developers.facebook.com/docs/ 文档的应用程序登录部分所述身份验证/

是否有什么情况会导致它们失效?

注意:这不是关于用户访问令牌的问题(有明确记录)。有一个相同的问题 http://facebook.stackoverflow.com/questions/7322063 /does-app-login-access-token-expire 错误地关闭,作为有关用户访问令牌的另一个问题的重复。

Do Facebook APP access tokens expire? These tokens are different than the USER tokens; they are acquired like this:

https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id={0}&client_secret={1})

as described in the App Login section of the document at http://developers.facebook.com/docs/authentication/.

Are there any circumstances under which they will become invalid?

NB: This is NOT a question about USER access tokens (which are clearly documented). There was an identical question http://facebook.stackoverflow.com/questions/7322063/does-app-login-access-token-expire wrongly closed as duplicate of another question about USER access tokens.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

允世 2025-01-04 20:39:47

根据 Facebook 文档

应用程序访问令牌是使用您的应用程序密钥进行签名的,并且不会
到期;如果您重新输入/重置您的应用程序,它将失效
秘密。

Per the Facebook documentation:

An App Access Token is signed using your app secret and will not
expire; it will be invalidated if you re-key/reset your application
secret.

揽月 2025-01-04 20:39:47

创建 APP_ACCESS_TOKEN 非常简单。
您可以使用您的应用 ID/API 密钥应用密钥

access_token = YOUR_APP_ID|YOUR_APP_SECRET

示例:1234587968 | bghyuifjk3438483249235903502035023504305

Creating an APP_ACCESS_TOKEN is really easy.
You can use your App ID/API Key and App secret

access_token = YOUR_APP_ID|YOUR_APP_SECRET

Example: 1234587968 | bghyuifjk3438483249235903502035023504305

会傲 2025-01-04 20:39:47

我确实知道,导致它们无效的一个条件是,如果您使用 Facebook 开发人员工具重置应用程序密钥。

我不知道使用OAuth方法生成App Token是否会导致它过期。但是,如果您扫描 Facebook 的 PHP SDK,您可能会注意到,非过期应用程序令牌是通过串联 app_id 和密钥创建的:

  /**
   * Returns the access token that should be used for logged out
   * users when no authorization code is available.
   *
   * @return string The application access token, useful for gathering
   *                public information about users and applications.
   */
  protected function getApplicationAccessToken() {
    return $this->appId.'|'.$this->apiSecret;
  }

警告:我永远不会在客户端代码中使用它,因为它会发布您的应用程序密钥。然而,在信任服务器环境中,这似乎是可行的方法。

为了测试这一点,我使用 OpenGraph 工具并删除了我的访问令牌并输入了代码示例中的串联值。然后我访问了我的应用程序的见解以验证它是否可以正常工作:

<APP_ID>/insights/application_active_users

I do know that one condition that will cause them to become invalid is if you reset the Application Secret using the Facebook developer tool.

I do not know if using the OAuth method to produce an App Token will cause it to have an expiration. However, if you scan Facebook's PHP SDK, you may notice that a non-expiring app token is made by concatenation app_id and secret:

  /**
   * Returns the access token that should be used for logged out
   * users when no authorization code is available.
   *
   * @return string The application access token, useful for gathering
   *                public information about users and applications.
   */
  protected function getApplicationAccessToken() {
    return $this->appId.'|'.$this->apiSecret;
  }

WARNING: I would never use this in client-code as it would publish your app secret. However, in a trust server environment, it seems like the way to go.

To test this, I went to the OpenGraph tool and erased my Access Token and typed in the concatenated value from the code sample. I then accessed my app's insights to verify that it would work:

<APP_ID>/insights/application_active_users
往昔成烟 2025-01-04 20:39:47

对我来说,答案不是找到一个不会过期的令牌(因为我不信任 Facebook),而是捕获过期的令牌并重置,而不占用我的用户时间。我发现了这个,我想你可能想看看。

“为了确保用户获得最佳体验,您的应用程序需要准备好捕获上述场景的错误。以下 PHP 代码向您展示了如何处理这些错误并检索新的访问令牌。

当您将用户重定向到身份验证时对话框中,如果用户已经授权您的应用程序,则不会提示用户授予权限,而不会出现任何面向用户的对话框,但是如果用户取消了您的应用程序的授权,则用户将需要重新授权。授权您的申请以获得访问令牌。”资源: https:// /developers.facebook.com/blog/post/2011/05/13/how-to--handle-expired-access-tokens/

For me, the answer is not to find a token that doesn't expire, (since I do not trust Facebook), but to catch the expiring token and reset without taking up my users time. I found this and thought you might want to check it out.

"To ensure the best experience for your users, your app needs to be prepared to catch errors for the above scenarios. The following PHP code shows you how to handle these errors and retrieve a new access token.

When you redirect the user to the auth dialog, the user is not prompted for permissions if the user has already authorized your application. Facebook will return you a valid access token without any user facing dialog. However if the user has de-authorized your application then the user will need to re-authorize your application for you to get the access_token." Resource: https://developers.facebook.com/blog/post/2011/05/13/how-to--handle-expired-access-tokens/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文