问题描述
当我以其他 Facebook 用户(不是主页管理员)身份使用我的应用时,我正在尝试研究如何在 Facebook 主页墙上发帖.
I am trying to work out how to post to a Facebook page wall, when using my app as a different Facebook User (who is not the Page Administrator).
我在测试时收到一系列错误消息:异常:200:用户尚未授权应用程序执行此操作
I get a range of error messages while testing:Exception: 200: The user hasn't authorized the application to perform this action
页面管理员已访问该应用并接受以下权限:publish_stream、manage_pages、offline_access
The page administrator has visited the app and accepted the following permissions: publish_stream, manage_pages, offline_access
这是我打算使用的代码:
Here is the code I plan to use:
// Insert Page Administrators ID here
// This user is not the same user that is currently logged in and using the app
// This user is the page administrator who has authorised:
// - manage_pages
// - offline_access
// - publish_stream
$user_id = '123456789';
// Insert Page ID here
$page_id = '123456789';
$accounts = $facebook->api('/'.$user_id.'/accounts');
foreach($accounts['data'] as $account)
{
if($account['id'] == $page_id)
{
$page_access_token = $account['access_token'];
echo "<p>Page Access Token: $page_access_token</p>";
}
}
// publish to the wall on your page
try
{
$result = $facebook->api(array( "uid" => $page_id,
"method" => "stream.publish",
"access_token" => $page_access_token,
"message" => $message, ));
}
catch (FacebookApiException $e)
{
error_log('FB Error: Could not post on Page Wall. Page ID: ' . $page_id);
error_log('FB Error Message: ' . $e);
}
注意:上面的代码中可能存在 PHP 错误,因为我只是在运行中对其进行了拼接,但这并不是我需要更正的 PHP 错误,而是我对我打算如何处理的逻辑理解过程.
Note: There may be PHP errors in the code above, as I just spliced it on the fly, but its not so much the PHP errors I need correcting, but more my logically understanding of how I am meant to go about this process.
问题:如果没有页面管理员的活动用户访问令牌,我将无法访问 $user_id/accounts 信息.
PROBLEM: I can't access the $user_id/accounts information without an active user access token for the Page Administrator.
我想要达到的最终结果是:1.) 普通 FB 用户进入应用并提交表单2.) 应用在FB页面墙上发布消息,该消息不归FB用户所有,但之前已获得页面管理员授权,具有以下权限manage_pages、publish_stream和offline_access
The end result that I'm trying to achieve is:1.) A normal FB user goes to the app and submits a form2.) The app posts a message on a FB Page wall, which is not owned by the FB user, but has previously been authorized by the Page Administrator with the following permissions manage_pages, publish_stream and offline_access
第一季度.既然页面管理员已经接受了适当的权限,为什么我不能在没有实际页面管理员用户登录网站的情况下生成一个活动用户访问令牌?
Q1. Since the Page Administrator has accepted the appropriate permissions, why can't I just generate an active user access token, without the actual Page Administrator user logging into the website?
第 2 季度.当我以不同的用户身份登录 Facebook 时(这就是我不使用/me/accounts 的原因),有没有一种方法可以获得与页面管理员 user_id 等效的/$user_id/accounts?
Q2. Is there a way I can get the equivalent of /$user_id/accounts for the Page Administrator user_id, when logged into Facebook as a different user (which is why I do not use /me/accounts)?
第三季度.请确认我对需要页面访问令牌发布到页面墙的理解是正确的(或者我是否需要页面管理员的用户 access_token - 参见 Q1)?
Q3. Please confirm that my understanding of needing the page access token to post to the page wall is correct (or do I need the user access_token for the Page Administrator - see Q1)?
第四季度.任何人都有关于每种类型的 access_token 实际可以访问的内容的方便资源吗?
Q4. Anyone have a handy resource on what each type of access_token can actually access?
如果您需要更多信息,请告诉我.最近几天我一直在研究这个,但我被卡住了.
If you need any more information, please let me know.I've spent the last few days working on this and I'm stuck.
谢谢!
推荐答案
您可以向页面管理员询问
manage_pages
和offline_access
.我在我的生产应用程序中执行此操作,以便能够将预定的帖子发布到页面的墙上.
You can ask the page admin for
manage_pages
along withoffline_access
. I do this in my production app to be able to post scheduled postings onto the pages' walls.
没有.不可能.这就是询问权限的全部意义所在.为什么不是每个人都可以管理其他人的页面.如果您可以管理任何人的页面而无需他们授予您访问权限,您能否想象一下?!?
Nope. Not possible. That's what asking permissions is all about. And why not everyone gets to administer everyone else's pages. Could you image if you could administer anyone's page without them granting you access?!?
要将页面作为页面发布到页面,您需要一个页面访问令牌.要以用户身份发布到页面的墙上,您需要一个用户访问令牌.
To post to the page as the page, you need a page access token. To post to page's wall as a user, you need a user access token.
是的,请参阅:https://developers.facebook.com/docs/reference/api/permissions 和 https://developers.facebook.com/docs/身份验证/
如果您对其中任何一个还有其他问题,请开始一个新问题.对于 stackoverflow 的用户来说,将 4 个问题合二为一,然后被问到每个问题的后续问题,这是不公平的.
这篇关于如何发布到 Facebook 页面(如何获取页面访问令牌 + 用户访问令牌)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!