持久的FB访问令牌用于服务器拉FB页面信息 [英] Long-lasting FB access-token for server to pull FB page info

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

问题描述

我知道有很多关于Facebook访问令牌和他们造成的悲伤的问题,但是尽管有很多实验和阅读了许多令人沮丧的博客文章(FB或其他),但我仍然在努力得到一个明确的答案满足我的需要让我简明扼要地分解我的过程:




  • 我正在创建一个网站,服务器端需要拉出帖子/状态从一个Facebook页面

  • 我是Facebook页面的管理员

  • 我创建了一个Facebook应用程序

  • 使用 Facebook Graph API Explorer ,我生成了一个短命的密钥,连接到我的应用程序和我的帐户,授予我的帐户许可,以查看我的页面的访问令牌

  • 我已将短命令的密钥转换为长寿命密钥60天)ala情景4从



这里是我被卡住的地方。我的60天钥匙工作正常,我的服务器可以从页面中提取所需的信息,但是我可以告诉你,没有办法以编程方式扩展这个60天的钥匙。我也不知道如何生成一个新的短寿命密钥,而不需要手动转到Facebook Graph API Explorer并创建一个。



由于是我的服务器对Facebook API的请求,而不是基于用户的系统(我可以轻松地请求用户再次授权Facebook应用程序)的请求,这将创建一个非常笨重的系统。由于Facebook不推荐使用 offline_access ,是否真的没有永久的方式让我的服务器从我自己的页面提取信息?我真的需要手动创建一个新的密钥,并且每60天就可以手动更新我的服务器吗?



还是有缺少的东西?



更新:


以前在此发现的步骤指南已被迁移到自己的答案



解决方案


这些是以前在问题中的步骤 - 已经迁移到这个答案。


发现有可能生成不到期的Facebook页面访问令牌(在@Igy的帮助下),对于所有寻求相同的人来说,这是一个清晰的,循序渐进的选择:


  1. Make确定您是FB页面的管理员,您希望从

  2. 中创建一个FB应用程序(应使用相同的用户帐户页面admin)

  3. 转到 Facebook Graph API Explorer

  4. 在右上方选择您从应用程序下拉列表创建的FB应用程序$ /
  5. 单击获取访问令牌

  6. 确保添加 manage_pages 权限

  7. 将短暂的访问令牌转换为通过这个Graph API调用一个长寿命的:
    https://graph.facebook.com/oauth/access_token?client_id=<你的应用程序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. 抓住 a您将从

  11. noreferrer> Lint 令牌,看到它被设置为到期:从不

应该这样做。您现在应该具有不会过期的Facebook页面访问令牌,除非:




  • 您更改您的Facebook帐户密码

  • 您将失去目标网页的管理员权限

  • 您删除或取消授权您的Facebook应用程序



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



如果您获得(#100)尝试访问节点类型(Page)上的非现有字段(帐户),请转到访问令牌调试器,复制用户ID 的值,并使用它替换步骤9中的URL的我部分。


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:

  • 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

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.

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?

Or is there something I'm missing?

Update:

The step-by-step guide that was previously found here has been migrated down into its own answer.

解决方案

These are the steps that were previously in the question - they have been migrated to this answer.

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. 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!

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

  • You change your Facebook account password
  • You lose admin access for the target page
  • You delete or de-authorize your Facebook App

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

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页面信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆