- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
简介
我有一个小的 Facebook 粉丝页面,我要在上面发布更新。为此,我使用了一个长期存在的访问 token ,该 token 每 60 天过期一次,其权限为:“manage_pages”和“publish_stream”。
经过研究,我没有找到“就是这样”的解决方案,所以我创建了一个新帖子来描述我的问题,同时将我目前发现的所有内容链接起来作为摘要。它长得有点大哈哈(我很抱歉)。
要获得短期访问 token ,我通常按照描述的这些步骤进行操作 here .
- Go to https://developers.facebook.com/tools/explorer/ and select your app from the first drop down menu, in the left.
- Click on the button "Get access token", and in the "Select Permissions" window, click in "Extended Permissions" and check manage_pages and publish_stream, and click in "Get Access Token" blue button.
- You may be asked in this step to garant permissions to your app to access to your Facebook account, accept.
- Next, click at the end of the text field next to the "GET" drop down, and replace the numbers for: me/accounts, and click in the blue button next to this text field.
- You'll get the tokens for all your pages, including your app page. Find your page name in the list, will look like this: "name": "Your page name"
- When you located your page, copy the access token for the page (will be really long), that can look like this: "access_token": "XXXXXXXX". Also copy the id of the page: "id": "XXXXX".
使用
https://graph.facebook.com/oauth/access_token?
client_id=[clientid]
&client_secret=[clientsecret]
&grant_type=fb_exchange_token
&fb_exchange_token=[shortlivedaccesstoken]
例如,无论是在浏览器中还是通过 curl 请求,我都会返回 60 天有效的访问 token 。 ( Source )
作为Facebook API documentation描述,长期存在的访问 token 无法刷新。当然,我可以使用上面的端点刷新 token 并获得一个新的长期 token 具有相同的到期日期返回。
编辑:要在粉丝页面墙上创建一个帖子(作为页面用户)我正在做某事。像这样:
$this->fb = new Facebook(array(
'appId' => [app-id],
'secret' => [app-secret]
));
//~Get data from DB here~
//~some error handling in case data fetching failed~
$fbToken = '';
$fbToken = *[facebook access token]*;
$mediaData = array(
'picture' => [picture-url],
'message' => [message],
'link' => [link],
'name' => [name],
'description' => [description],
'access_token' => $fbToken
);
try {
$post_id = $this->fb->api('/' . [fb-page-id] . '/feed', 'post', $mediaData);
} catch(FacebookApiException $e) {
//log file output
}
问题
您只能使用短期访问 token 来获取新的长期访问 token 。
@maxim-aniskov 描述了一种获取新的短期访问 token 的方法 here .遇到同样的问题,它在第一次获取时工作一次。接受的答案涉及删除当前权限。
此外,在 this post评论中已经暗示,如果没有用户交互,即使是短暂的访问 token 也无法刷新。
最后,正如您所看到的,有很多人遇到了同样的乐趣 here too .
我什至在某处读到可以刷新现有的长期访问 token ,但前提是它即将过期。没有关于“即将到期”的时间表的信息。 (5 天不是)
最终他们都没有进一步帮助我。
问题
综上所述~
How to get a new short lived access token with the previously used permissions (manage_pages and publish_stream) querying an API endpoint?
是否真的只能通过撤销先前授予的访问权限才能实现?我正在尝试刷新其访问 token 的网站是关于发布实时更新,所以我希望几乎没有停机时间.. 而不是每次旧 token 过期时在 graph api explorer 中手动生成一个新的短期 token 或即将到期,我宁愿只按一个按钮来完成。
最佳答案
其实你对流程很困惑!让我来解释一下这个访问 token 是如何工作的——
首先,从 Graph API Explorer 获取访问 token 只是一种方式——当然不是最好的方式。 (但在你的情况下,这似乎很好,因为我认为你只是从你的帐户管理页面,而不是为其他 Facebook 用户管理页面 - 如果我错了请纠正我)。
通常,facebook 集成用于获取 facebook 用户的访问权限并执行某些事件或获取用户的数据,这是通过实现 facebook login 来完成的。 . Facebook 登录考虑了用户授予的权限并返回 access token。 - 这是用户访问 token
/me/accounts
).现在,好处是 - 您可以扩展
永不过期的页面访问 token !我已经解释了这些步骤
here .
如果您想以用户/管理员的名义发帖,您可以使用用户访问 token ,它可以通过发出您已经解释过的\GET 请求来扩展。现在当你说-
I've even read that an existing long lived access token can be refreshed but only if it's about-to-expire. There is no information in which timeframe 'about-to-expire' lies. (5 days ain't)
这个说法是错误的!您可以随时扩展 token 。今天你有一个 60 天到期的代币,明天它可以再次延长,最多 60 天到期。要刷新扩展 token ,您必须重复第一次用于生成扩展 token 的步骤,即 - 使用登录流程或图形 api 资源管理器获取访问 token (正常的)(是的 - 没有其他方法获取访问 token )并发出\GET 请求以获取扩展 token 。就是这个!
你问-
How to get a new short lived access token with the previously used permissions (manage_pages and publish_stream) querying an API endpoint?
别担心,下次当您尝试获取访问 token 时,它将拥有相应的权限,因为您已经授权了该应用程序。你不需要为此处理任何事情!
编辑
如果您不想使用 Graph API Explorer,您可以使用 JS/PHP/其他语言编写一个小脚本并实现 facebook 登录 - 获取访问 token - 并扩展该 token (哦等等!你没有告诉你如何创建帖子?你只能用你的脚本来做到这一点 - 足够简单!)。祝你好运!
关于php - 如何在不使用 api 资源管理器的情况下获取具有以前使用的权限的新 'short lived' facebook 访问 token (服务器端)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22732843/
我是 firebase 的新手,我正在尝试分页查询。我喜欢有一个“下一个”和“上一个”按钮。我的下一个按钮工作正常,我的问题是单击上一个 引用:https://firebase.google.com/
抱歉,标题这么蹩脚,但我只是不知道该放什么,希望你能理解。另外,我不知道以前是否有人问过类似的问题,因为我不知道合适的关键字 - 因此也无法用谷歌搜索。 基本上...在查看preg_match_all
我想在 TFS 中 check out 一个检入文件的先前版本。我可以轻松获得特定文件的变更集 ID 列表,但无法弄清楚如何 checkout 以前的版本。 我目前的代码: var workspace
我想使用 @FunctionalInterface来 self 代码中的 Java 8,但我希望能够将生成的类文件与 Java 6 一起使用。我认为我应该将源版本设为 1.8 , 目标版本为 1.6
自从 versions 被删除以来,我一直无法找到安装以前版本软件的方法。命令并点击 Homebrew。我在 2008 Mac Pro (3,1) 上运行 macOS 10.14.3 (Mojave)
当我开始当前的项目时,App Store 中已经有一个应用程序。此应用程序仅适用于 iPhone。 我的第一个任务是测试和构建一个也可以在 iPod Touch 上运行的版本。 大约 3 周前,App
我在 GitHub 上有一个曾经是 fork 的 repo,但现在不是了,因为我已经删除了原始项目的任何痕迹并开始了一个同名的新项目。 但是,GitHub 仍然表示该项目是 fork 的。有什么方法可
我是一名优秀的程序员,十分优秀!