Facebook访问令牌无效-尝试发布到Facebook网站“页面"通过应用程序使用cron [英] facebook access token is invalid - trying to post to facebook website-"page" via app using a cron
问题描述
我正在尝试通过服务器上的cron发布到网站的Facebook粉丝页面.
I am trying to post to my website's Facebook fan-page via a cron on my server.
我在Facebook上创建了一个名为"John Doe"的用户,在网站的Facebook粉丝页面上让他成为管理员,然后以沙盒模式从该用户创建了一个应用程序,因此只有他"John Doe"可以运行.
I created a user on Facebook named "John Doe", i made him admin on my website's Facebook fan-page and then i created an app from that user in sandbox mode, so only he, "John Doe" can "run" it.
我从运行它的"John Doe"授予了我的应用必要的权限.
I gave the necessary permissions to my app from "John Doe" who runs it.
我可以通过developers.facebook.com手动获取访问令牌,并使用它们通过"John Doe"的应用程序从我的php cron脚本发布到我的网站的Facebook粉丝页面.
I can manually get the access tokens through developers.facebook.com and use them to post from my php cron script to my website's Facebook fan-page through "John Doe"'s app.
问题是,要使其正常工作,必须登录我的"John Doe" facebook用户.
The problem is, that in order for this to work, my "John Doe" facebook user must be logged-in.
我应该怎么做,我的网站php cron脚本始终具有自动有效的访问令牌,因此它可以通过管理员"John Doe"正在使用并允许访问的应用程序成功发布到网站的Facebook粉丝页面上?
现在,我以"John Doe"的身份手动登录到Facebook,并将访问令牌从developers.facebook.com复制粘贴到我的php脚本中,并且可以正常工作.
Right now i manually log-in to facebook as "John Doe" and i am copy-pasting the access token from developers.facebook.com to my php script and it works.
(我网站的Facebook粉丝页面上的完整帖子显示为通过m-y-a-p-p共享链接的m-y-w-e-b-s-i-t-e",因此,我很确定除访问令牌外,其他所有内容都可以)
(Succesfull posts in my website's Facebook fan-page are shown like "m-y-w-e-b-s-i-t-e shared a link via m-y-a-p-p" so i am pretty sure that apart from the access-tokens everything else is ok)
提前谢谢
推荐答案
This question is very similar to my own question and I've spent 2 days trying to solve this. The solution is super simple.
-
将您的应用设置为本地/桌面,这样您可以获得60天的令牌(稍后将其转换为永久令牌).为此,请转到 https://developers.facebook.com/apps/编辑设置>高级>在应用程序"类型中选择本机/桌面".
Set your app to Native/Desktop so you can get a 60-day token (you'll turn this to permanent later). Do this by going to https://developers.facebook.com/apps/ Edit settings > Advanced > Choose Native/Desktop in the App type.
转到 https://developers.facebook.com/tools/explorer/选择您的应用,然后获取访问令牌
Go to https://developers.facebook.com/tools/explorer/ select your app, and Get Access Token
在扩展权限标签中,选择manage_pages
和publish_stream
现在您有60天的临时令牌.
Now you have a 60-day temporary token.
要获取永久令牌,请转到此处并使用临时令牌:https://graph.facebook.com/me/accounts?access_token=REPLACE_THIS_WITH_YOUR_TEMPORARY_TOKEN
To get your permanent token, go here and use your temporary token: https://graph.facebook.com/me/accounts?access_token=REPLACE_THIS_WITH_YOUR_TEMPORARY_TOKEN
您应该看到您作为管理员的所有Facebook页面的永久访问令牌
You should see permanent access token to all Facebook pages which you are an admin
这篇关于Facebook访问令牌无效-尝试发布到Facebook网站“页面"通过应用程序使用cron的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!