本文介绍了用于服务器拉取 FB 页面信息的持久 FB 访问令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有很多关于 Facebook 访问令牌及其造成的悲痛的问题,但尽管进行了大量实验并阅读了许多令人沮丧的模糊博客文章(FB 和其他),我仍然在努力获得明确的答案到我的需要.让我简明地分解我到目前为止的过程:

I'm aware that there are many questions about Facebook access-tokens and the grief they cause, but despite much experimentation and reading many frustratingly vague blog articles (FB and otherwise), I'm still struggling to get a clear answer to my needs. Let me succinctly break down my process so far:

  • 我正在创建一个网站,服务器端需要从单个 Facebook 页面中提取帖子/状态
  • 我是该 Facebook 主页的管理员
  • 我创建了一个 Facebook 应用
  • 使用 Facebook Graph API Explorer,我生成了一个短期密钥,连接到我的应用程序和我的帐户,授予我的帐户查看我的页面的访问令牌的权限
  • 我已将我的短期密钥转换为长期密钥(60 天)ala 场景 4,来自 这个
  • I am creating a site that, server-side, needs to pull the posts/statuses from a single Facebook Page
  • I am an admin of that Facebook Page
  • I have created a Facebook App
  • Using the Facebook Graph API Explorer, I've generated a short-lived key, connected to my app and my account, that grants permission to my account to view the access-tokens for my pages
  • I've converted my short-lived key to a long-lived key (60 days) ala scenario 4 from this

这就是我被卡住的地方.我的 60 天密钥可以让我的服务器从页面中提取所需的信息,但据我所知,没有办法以编程方式扩展 60 天密钥.我也不知道有什么方法可以在不手动转到 Facebook Graph API Explorer 并创建一个新的短期密钥的情况下生成一个.

And here's where I am stuck. My 60 day key works fine for my server to pull the info needed from the page, but as far I can tell, there's no way to programmatically extend that 60 day key. I also do not know of a way to generate a new short-lived key without manually going to the Facebook Graph API Explorer and creating one.

由于是我的服务器向 Facebook API 发出请求,而不是基于用户的系统(我可以轻松地请求用户再次授权 Facebook 应用程序),这会创建一个非常笨重的系统.由于 Facebook 弃用了 offline_access,真的没有永久的方法可以让我的服务器从我自己的页面中提取信息吗?我真的必须每 60 天手动创建一个新密钥并用它手动更新我的服务器吗?

Since it is my server making the requests to the Facebook API and not a user-based system (where I could easily request that a user authorize the Facebook app again), this creates a very clunky system. Since Facebook deprecated offline_access, is there really no permanent way to have my server pull info from my own page? Will I really have to create a new key by hand and manually update my server with it every 60 days?

还是我遗漏了什么?

更新:

之前在此处找到的分步指南已向下迁移到其自己的答案.

推荐答案

发现可以生成不会过期的 Facebook 页面访问令牌(在@Igy 的帮助下),这里有一个清晰的分步指南,适用于所有希望相同的人:

Having found that it is possible to generate a Facebook Page Access Token that does not expire (with help from @Igy), here is a clear, step-by-step quide for all those looking to the same:

  1. 确保您是要从中提取信息的 FB 页面的管理员
  2. 创建一个 FB 应用程序(应该使用与页面管理员相同的用户帐户)
  3. 前往 Facebook Graph API Explorer
  4. 在右上角,从应用程序"下拉列表中选择您创建的 FB 应用程序
  5. 点击获取访问令牌"
  6. 确保您添加了 manage_pages 权限
  7. 通过调用此 Graph API 将这个短期访问令牌转换为长期访问令牌:https://graph.facebook.com/oauth/access_token?client_id=<你的FB App ID >&client_secret=<你的FB App secret>&grant_type=fb_exchange_token&fb_exchange_token=<你的短-实时访问令牌>
  8. 获取返回的新的长期访问令牌
  9. 使用新的长期访问令牌进行 Graph API 调用以查看您的帐户:https://graph.facebook.com/me/accounts?access_token=
  10. 获取要从中提取信息的页面的 access_token
  11. Lint 令牌以查看其设置为 Expires: Never!
  1. Make sure you are the admin of the FB page you wish to pull info from
  2. Create a FB App (should be with the same user account that is the page admin)
  3. Head over to the Facebook Graph API Explorer
  4. On the top right, select the FB App you created from the "Application" drop down list
  5. Click "Get Access Token"
  6. Make sure you add the manage_pages permission
  7. Convert this short-lived access token into a long-lived one by making this Graph API call:https://graph.facebook.com/oauth/access_token?client_id=<your FB App ID >&client_secret=<your FB App secret>&grant_type=fb_exchange_token&fb_exchange_token=<your short-lived access token>
  8. Grab the new long-lived access token returned back
  9. Make a Graph API call to see your accounts using the new long-lived access token: https://graph.facebook.com/me/accounts?access_token=<your long-lived access token>
  10. Grab the access_token for the page you'll be pulling info from
  11. Lint the token to see that it is set to Expires: Never!

应该可以.您现在应该拥有一个不会过期的 Facebook 页面访问令牌,除非:

That should do it. You should now have a Facebook Page Access Token that doesn't expire, unless:

  • 您更改了 Facebook 帐户密码
  • 您失去了目标页面的管理员权限
  • 您删除或取消对您的 Facebook 应用的授权

任何这些都会导致访问令牌无效.

Any of these will cause the access token to become invalid.

如果您收到 (#100) Tried accessing nonexistent field (accounts) on node type (Page),请转到 Access Token Debugger,复制User ID的值,并用它替换步骤中URL的me"部分9.

If you are getting (#100) Tried accessing nonexisting field (accounts) on node type (Page), go to the Access Token Debugger, copy the value of User ID, and use it to replace the "me" part of the URL in step 9.

这篇关于用于服务器拉取 FB 页面信息的持久 FB 访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 19:12