facebook:永久页面访问令牌? [英] facebook: permanent Page Access Token?

查看:47
本文介绍了facebook:永久页面访问令牌?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从事一个项目,该项目将 Facebook 页面作为其数据源之一.它定期从中导入一些数据,不涉及 GUI.然后我们使用一个网络应用程序来显示我们已有的数据.

I work on a project that has facebook pages as one of its data sources. It imports some data from it periodically with no GUI involved. Then we use a web app to show the data we already have.

并非所有信息都是公开的.这意味着我必须访问数据一次,然后保留它.然而,我不知道这个过程,我还没有找到一个很好的教程.我想我需要一个 access_token,我怎样才能从用户那里一步一步地得到它?用户是 facebook 页面的管理员,他是否需要将我们的一些 FB 应用程序添加到页面中?

Not all the information is public. This means I have to get access to the data once and then keep it. However, I don't know the process and I haven't found a good tutorial on that yet. I guess I need an access_token, how can I get it from the user, step by step? The user is an admin of a facebook page, will he have to add some FB app of ours to the page?

感谢@phwd 的提示.我制作了一个教程,如何获得永久页面访问令牌,即使 offline_access 不再存在.

Thanks @phwd for the tip. I made a tutorial how to get a permanent page access token, even with offline_access no longer existing.

我刚刚发现这里有答案:服务器拉取FB页面信息的持久FB访问令牌

I just found out it's answered here: Long-lasting FB access-token for server to pull FB page info

推荐答案

按照 Facebook 的 扩展页面令牌文档 我能够获得一个不会过期的页面访问令牌.

Following the instructions laid out in Facebook's extending page tokens documentation I was able to get a page access token that does not expire.

除非另有说明,否则我建议对所有这些步骤使用 Graph API Explorer.

I suggest using the Graph API Explorer for all of these steps except where otherwise stated.

如果您已有应用,请跳至第 1 步.

  1. 转到我的应用.
  2. 点击+ 添加新应用".
  3. 设置网站应用.

您无需更改其权限或任何内容.您只需要一个在您使用完访问令牌之前不会消失的应用.

You don't need to change its permissions or anything. You just need an app that wont go away before you're done with your access token.

  1. 转到Graph API Explorer.
  2. 选择您要为其获取访问令牌的应用程序(在应用程序"下拉菜单中,而不是我的应用程序"菜单中).
  3. 点击获取令牌">获取用户访问令牌".
  4. 在弹出窗口中的扩展权限"选项卡下,选中manage_pages".
  5. 点击获取访问令牌".
  6. 从有权管理目标页面的 Facebook 帐户授予访问权限.请注意,如果此用户无法访问,最终的、永不过期的访问令牌可能会停止工作.

出现在访问令牌"字段中的令牌是您的短期访问令牌.

The token that appears in the "Access Token" field is your short-lived access token.

按照 Facebook 文档中的这些说明,制作一个GET 请求到

Following these instructions from the Facebook docs, make a GET request to

https://graph.facebook.com/v2.10/oauth/access_token?grant_type=fb_exchange_token&client_id={app_id}&client_secret={app_secret}&fb_exchange_token={short_lived_token}

https://graph.facebook.com/v2.10/oauth/access_token?grant_type=fb_exchange_token&client_id={app_id}&client_secret={app_secret}&fb_exchange_token={short_lived_token}

输入您应用的 ID 和密码以及在上一步中生成的短期令牌.

entering in your app's ID and secret and the short-lived token generated in the previous step.

无法使用 Graph API Explorer.出于某种原因,它被这个请求卡住了.我认为这是因为响应不是 JSON,而是查询字符串.由于它是 GET 请求,因此您可以直接在浏览器中访问该 URL.

You cannot use the Graph API Explorer. For some reason it gets stuck on this request. I think it's because the response isn't JSON, but a query string. Since it's a GET request, you can just go to the URL in your browser.

响应应如下所示:

{"access_token":"ABC123","token_type":"bearer","expires_in":5183791}

{"access_token":"ABC123","token_type":"bearer","expires_in":5183791}

ABC123"将是您的长期访问令牌.您可以将其放入Access Token Debugger 进行验证.在到期"下,它应该有2 个月"之类的内容.

"ABC123" will be your long-lived access token. You can put it into the Access Token Debugger to verify. Under "Expires" it should have something like "2 months".

使用长期访问令牌,向

Using the long-lived access token, make a GET request to

https://graph.facebook.com/v2.10/me?access_token={long_lived_access_token}

id 字段是您的帐户 ID.下一步将需要它.

The id field is your account ID. You'll need it for the next step.

发出 GET 请求

https://graph.facebook.com/v2.10/{account_id}/accounts?access_token={long_lived_access_token}

https://graph.facebook.com/v2.10/{account_id}/accounts?access_token={long_lived_access_token}

JSON 响应应该有一个 data 字段,在该字段下是用户有权访问的项目数组.找到您想要永久访问令牌的页面的项目.access_token 字段应该有您的永久访问令牌.复制它并在 Access Token Debugger 中进行测试.在到期"下,它应该说从不".

The JSON response should have a data field under which is an array of items the user has access to. Find the item for the page you want the permanent access token from. The access_token field should have your permanent access token. Copy it and test it in the Access Token Debugger. Under "Expires" it should say "Never".

这篇关于facebook:永久页面访问令牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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