如何使用页面名称而不是用户名将状态发布到 Facebook 页面?
如何使用 PHP SDK 和图形 API 将状态消息发布到页面(而不是用户个人资料),同时让状态消息看起来是由页面 ID 而不是用户 ID 发布的?我的应用程序可以成功地将状态更新发布到页面墙上,但它似乎是来自管理员用户名的墙贴,而不是像在 Facebook 上本地发布的那样从页面名称发布状态更新。换句话说,如果页面名称是“Cool Stuff”并且用户名是“Joe Smith”,我想在页面上发布来自“Cool Stuff”的状态更新,但我的应用程序帖子的更新显示来自“Joe Smith”。我已经在状态数组中明确设置了页面 id 和页面名称,但它似乎没有帮助。这是我当前的代码:
$post_info = array(
'access_token' => $facebook->access_token,
'type' => 'status',
'message' => 'Hello World!',
'from' => array('id' => $page_id, 'name' => $page_name)
);
$facebook->api('/' . $page_id . '/feed/', 'post', $post_info);
有什么建议吗?
How can I post a status message to a page (not a user profile) using the PHP SDK and graph API while having the status message appear to be posted by the page ID rather than a user ID? My app can successfully post a status update to the page wall but it appears to be a wall post from the admin's username rather than a status update from the page name as it would if posted locally on Facebook. In other words if the page name is "Cool Stuff" and the user name is "Joe Smith", I want to post a status update on the page from "Cool Stuff" but the updates my app posts appear from "Joe Smith". I'm already explicitly setting the page id and page name in the status array but it doesn't seem to help. Here's my current code:
$post_info = array(
'access_token' => $facebook->access_token,
'type' => 'status',
'message' => 'Hello World!',
'from' => array('id' => $page_id, 'name' => $page_name)
);
$facebook->api('/' . $page_id . '/feed/', 'post', $post_info);
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在 FB API 身份验证文档中找到了解决方案:
https://developers.facebook.com/ docs/authentication/
答案就在页面底部附近。搜索“页面登录”部分。基本上,您的应用程序必须查询 FB 以获取用户页面访问令牌的列表。您找到要充当的页面的令牌,并将其替换为状态消息帖子中的普通用户访问令牌。因此,我添加了以下代码来获取用户的页面访问令牌(您的应用程序必须具有 manage_pages 权限才能正常工作):
$all_accounts = $facebook->api('/me/accounts');
如果您使用 print_r 转储 $all_accounts,您将看到它是页面名称和访问令牌的数组。获取所需页面的令牌,并将 $facebook->access_token (用户的访问令牌)替换为我在最初问题中发布的代码中的页面令牌。它将以页面管理员而不是用户的身份将状态发布到页面。
I found the solution to this in the FB API authentication docs here:
https://developers.facebook.com/docs/authentication/
The answer is way down near the bottom of the page. Search for the "page login" section. Basically your app has to query FB for a list of the user's page access tokens. You find the token for the page you want to act as and substitute it for the normal user access token in the status message post. So I added this code to grab the user's page access tokens (your app has to have the manage_pages permission for this to work):
$all_accounts = $facebook->api('/me/accounts');
If you use print_r to dump $all_accounts, you'll see it's an array of page names and access tokens. Grab the token for page you want and replace $facebook->access_token (the user's access token) with the page token in the code I posted in my initial question. It will post the status to the page as the page admin rather than the user.
如果您是该页面的管理员,只需进行身份验证并将状态作为页面的 UserID 而不是您的 UserID 发送即可。它们是两个不同的实体。
这样做将解决您的问题:-) 只需确保首先针对您的应用程序手动验证您的页面:-)
If you are the admin of that page just simply authenticate and send the status as the page's UserID instead of your UserID. They are 2 different entities.
Doing that will solve your problem :-) Just make sure to manually authenticate your page against your App first :-)