简体   繁体   English

Facebook Graph API访问令牌

[英]Facebook Graph API Access Token

I've spent the several hours reading posts here, and following links (many of them dead) to developer.facebook.com. 我已经花了几个小时在这里阅读帖子,并关注了到developer.facebook.com的链接(其中很多已经死了)。

How can I display my most recent FB post on my external website? 如何在我的外部网站上显示我最近的FB帖子? I can do this by manually updating access token every couple of hours. 我可以通过每两个小时手动更新一次访问令牌来做到这一点。 Or I could ask my website visitors to log into facebook when they visit my website. 或者,我可以要求我的网站访问者在访问我的网站时登录Facebook。 Obviously neither is a desirable solution. 显然,这都不是理想的解决方案。

The best I've been able to find is Facebook's offline-access-removal instructions https://developers.facebook.com/roadmap/offline-access-removal/#extend_token . 我能找到的最好的方法是Facebook的脱机访问删除说明https://developers.facebook.com/roadmap/offline-access-removal/#extend_token In order to proceed, it seems I need an App ID. 为了继续,看来我需要一个App ID。 I'm making quite a few assumptions that this is the right approach. 我做出许多假设,认为这是正确的方法。 Can anyone explicitly confirm that this effort will eventually work? 谁能明确确认这项努力最终会成功? Or do I need to look elsewhere? 还是我需要寻找其他地方?

You extend a short lived access-token for a long lived access token. 您将一个短暂的访问令牌扩展为一个长期的访问令牌。 The only person that needs to login is the user you want the data from. 唯一需要登录的人是您要从中获取数据的用户。 Then you save the access_token to a database with the expiry and retrieve when needed for everyone else. 然后,将access_token保存到到期的数据库中,并在其他所有人需要时进行检索。 In short steps 简短的步骤

  • Load your SQL with the access_token structure 使用access_token结构加载SQL
  • Create a configuration file for the database 为数据库创建配置文件
  • Create helper functions for database actions such as connecting and querying 创建用于数据库操作(例如连接和查询)的辅助函数
  • Load the Facebook SDK for the administration view page (this is where you want the login action to get the access_token) 为管理视图页面加载Facebook SDK(在此处您希望登录操作获取access_token)
  • Update the database with access_token retrieved 使用检索到的access_token更新数据库
  • Use the front end to select the access_token from the database 使用前端从数据库中选择access_token

There is a detailed workout for a page display though it wouldn't be that hard to modify it for long lived access tokens 对于页面显示,有详细的锻炼方法,尽管对于长期使用的访问令牌来说,修改它并不难

An example can be found at https://github.com/phwd/hellopageposts 可以在https://github.com/phwd/hellopageposts找到一个示例

Source: http://philippeharewood.com/facebook/getting-your-facebook-page-on-your-website-with-access-tokens/ 资料来源: http : //philippeharewood.com/facebook/getting-your-facebook-page-on-your-website-with-access-tokens/

  1. https://developers.facebook.com/docs/howtos/login/server-side-login/ follow all the steps. https://developers.facebook.com/docs/howtos/login/server-side-login/遵循所有步骤。
  2. https://developers.facebook.com/roadmap/offline-access-removal/#extend_token https://developers.facebook.com/roadmap/offline-access-removal/#extend_token

The stumbling block for me is that the first page gives you sample scripts (PHP and Javascript), whereas the second page is the basic REST API. 对我而言,绊脚石是第一页提供了示例脚本(PHP和Javascript),而第二页是基本的REST API。 I used curl, and will probably create a shell script when my access token expires in 60 days. 我使用curl,并且当我的访问令牌在60天后过期时,可能会创建一个shell脚本。 Someone with more cut&paste confidence than I have could do the whole thing with a browser. 剪切和粘贴信心比我更强大的人可以使用浏览器完成整个操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM