如何使用 PHP 发布到 Facebook 页面 [英] How to post to a Facebook page with PHP
问题描述
我想使用 PHP 从我的网站发布到我自己的 Facebook 页面的墙上.
I would like to post to my own Facebook page's wall from my website using PHP.
我有以下几点:
- Facebook 应用程序,带有 AppID、AppSecret、ApiKey
- Facebook 主页,带有 PageID
- 我自己的 Facebook 帐户 - 我是上述应用程序和页面的管理员和创建者.
- Facebook Application with AppID, AppSecret, ApiKey
- Facebook Page with PageID
- my own Facebook account - I'm the admin and the creator of the application and page mentioned above.
例如我写了一篇博文,我想在我的 Facebook 页面的墙上得到名称、简短描述和图片.或者我想每天自动在Facebook页面上发布一些文章作为cron作业.
E.g. I write a blog post, and I'd like to get the name, the short description and a picture on my Facebook page's wall. Or I would like to publish some articles on the Facebook page every day automatically as a cron job.
您能否提供一个分步教程来完成此操作?
Could you provide a step-by-step tutorial how to accomplish this?
我读过这篇关于 Facebook 登录的文章:
https://developers.facebook.com/docs/facebook-login/
但我仍然不知道在我的代码中写什么.
I've read this article about Facebook Login:
https://developers.facebook.com/docs/facebook-login/
but I still don't know what to write in my code.
这是我发送应用访问令牌请求的方式:
This is how I send a request for an App Access Token:
$url = 'https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id='
.Yii::app()->params['FacebookAppID']
.'&client_secret='
.Yii::app()->params['FacebookSecret'];
响应与此类似(假符号):
The response is similar to this (fake symbols):
access_token=326584076429|ax3-D39YbpDcR9rMRQn_fMvNu_s
access_token
是什么?应用程序访问令牌?如何获取用户访问令牌?
What access_token
is it? Application Access Token? How to get a User Access Token?
我尝试使用这里的访问令牌:
https://developers.facebook.com/tools/explorer?method=GET&path=me%2Faccounts但我收到以下错误消息:
I tried to use the access token from here:
https://developers.facebook.com/tools/explorer?method=GET&path=me%2Faccounts
but I got the following error message:
必须使用活动访问令牌来查询有关当前用户的信息
那么我应该如何获得正确的访问令牌?
So how should I obtain the right access token?
如何在没有任何客户端交互的情况下在我的应用程序中获取正确的 Facebook 令牌?
我是 Facebook 应用程序和 Facebook 主页的管理员和创建者.
How can I get the right Facebook tokens in my application without any client interaction?
I'm the admin and the creator of the Facebook Application and the Facebook Page.
推荐答案
循序渐进
- 验证作为页面管理员的用户(您自己)
- 请求扩展访问令牌(在 offline_access 消失后获得 60 天的变化).请参阅 https://developers.facebook.com/docs/offline-access-deprecation/
- 调用图谱 API
me/accounts
并在结果列表中搜索以找到您感兴趣的页面 - 从页面中获取页面访问令牌并开始使用它来调用 post
- 可能可以获得第 2 步中描述的页面访问令牌的扩展访问令牌,请尝试告诉我们是否也可以为页面访问令牌完成此操作.
- Authenticate a user that is a page admin (yourself)
- Request an extended access token (to get a 60 day variety as offline_access is gone). See https://developers.facebook.com/docs/offline-access-deprecation/
- Call Graph API
me/accounts
and search thru the resulting list to find the page you're interested in - Take the page access token from the page and start using that for the calls to post
- It might be possible to get an extended access token for a page access token like described in step 2, please try and let us know if that can be done for page access token too.
您可以在 https://developers.facebook.com/tools/explorer一个>
快乐编码!
编辑
要为任何用户获取没有对话框的访问令牌,您可以使用 https://developers.facebook.com/tools/access_token/ 获取访问令牌.
For getting an access token without dialogs for any user, you can use https://developers.facebook.com/tools/access_token/ to get an access token.
这篇关于如何使用 PHP 发布到 Facebook 页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!