Facebook Graph API v3.1 开发人员访问令牌权限限制
Facebook Graph API v3.1 Access Token Permission Limitations For Developers
如您所知,Facebook 已将它 API 升级到 V3.1,现在正在缓慢地杀死旧的 API 和应用程序,因此我们必须迁移到新的 API一些在 SPAM 网站上很好但对开发人员也很难的艰难决定。
提醒:Graph API v2.7 将于 2018 年 10 月 5 日弃用。请使用 API Upgrade Tool to understand how this might impact your app. For more details see the changelog
现在我创建了一个新的 FB 应用程序,其中的一些设置如下面的屏幕截图所示 Post 在我自己的页面上而不是个人资料 但出现了下面提到的错误也是。
然后我使用下面的代码 post 在我自己的页面上,我是创建此应用程序的同一帐户的所有者。
<?php
$page_access_token = 'GENERAL_ACCESS_TOKEN';
$page_id = 'OWN_PAGE_ID';
// From https://developers.facebook.com/tools/explorer
$data['message'] = "Text_Message";
//$data['picture'] = "http://www.example.com/image.jpg";
//$data['link'] = "http://www.example.com/";
//$data['caption'] = "Caption";
//$data['description'] = "Description";
$data['access_token'] = $page_access_token;
$post_url = 'https://graph.facebook.com/'.$page_id.'/feed';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $post_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$return = curl_exec($ch);
echo $return;
curl_close($ch);
?>
现在当我 运行 上面的代码时,我得到了下面的错误...
{"error":{"message":"(#200) Requires either publish_to_groups permission and app being installed in the group, or manage_pages and publish_pages as an admin with sufficient administrative permission","type":"OAuthException","code":200,"fbtrace_id":"XXXXXXXXX"}}
现在我的问题是我可以从哪里允许我的应用程序获得这些权限,因为我允许的地方都没有看到这些名称(publish_to_groups
、manage_pages
和 publish_pages
等)如上图所示。
注意:我现在创建的所有内容和代码,所以我需要使用新发布的解决方案 API 3.1.
更新:
我的朋友告诉我允许所有权限让我的代码工作,如下面的屏幕截图所示,但我无法在我的应用程序中查看这些权限。我需要所有这些。如何获得它们?
在我看来,您使用的是用户访问令牌。
要获取页面访问令牌,您应该调用端点:
https://graph.facebook.com/v3.1/{user-id or me}/accounts
获取页面列表和每个页面的访问令牌。
或者:
https://graph.facebook.com/v3.1/{page-id}?fields=access_token
如果您已经知道要访问的页面 post。
获得页面访问令牌后,您可以调用 feed
端点。
看看这里:
https://developers.facebook.com/docs/pages/access-tokens
我尝试了很多东西,然后我在 Facebook 开发者指南上发现,在新的更新之后,如果应用程序上线,没有人可以获得以下所有显示的权限。要在您的应用上线后获得所有这些权限,您必须申请权限以进行审查,否则您可以在开发模式下免费获得所有权限但它只对您有效。
如您所知,要获得您的应用程序中的所有权限供您自己使用,您无需审查您的应用程序或任何其他内容即可获得它。您可以在下面看到一个应用程序的常规设置。
您只需关闭实时模式,将您的应用程序置于开发模式,如下图和上方的屏幕截图所示。
完成此操作后,只需转到 Graph API Explorer and click "Get Token" button then select "Get User Access Token" and here you will get the pop up as shown in the first screenshot of this Answer where you can select your desired scopes and click "Get Access Token". It will raise a POPUP where it will need your permission to allow and then it will return you the Access Token. (You Can Extend Your Access Token To 60 Days)
注意:此令牌将 post 在您的页面上仅对您可见,因为您的应用未上线,因此您的应用所做的每个 activity 仅供您使用.
如您所知,Facebook 已将它 API 升级到 V3.1,现在正在缓慢地杀死旧的 API 和应用程序,因此我们必须迁移到新的 API一些在 SPAM 网站上很好但对开发人员也很难的艰难决定。
提醒:Graph API v2.7 将于 2018 年 10 月 5 日弃用。请使用 API Upgrade Tool to understand how this might impact your app. For more details see the changelog
现在我创建了一个新的 FB 应用程序,其中的一些设置如下面的屏幕截图所示 Post 在我自己的页面上而不是个人资料 但出现了下面提到的错误也是。
然后我使用下面的代码 post 在我自己的页面上,我是创建此应用程序的同一帐户的所有者。
<?php
$page_access_token = 'GENERAL_ACCESS_TOKEN';
$page_id = 'OWN_PAGE_ID';
// From https://developers.facebook.com/tools/explorer
$data['message'] = "Text_Message";
//$data['picture'] = "http://www.example.com/image.jpg";
//$data['link'] = "http://www.example.com/";
//$data['caption'] = "Caption";
//$data['description'] = "Description";
$data['access_token'] = $page_access_token;
$post_url = 'https://graph.facebook.com/'.$page_id.'/feed';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $post_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$return = curl_exec($ch);
echo $return;
curl_close($ch);
?>
现在当我 运行 上面的代码时,我得到了下面的错误...
{"error":{"message":"(#200) Requires either publish_to_groups permission and app being installed in the group, or manage_pages and publish_pages as an admin with sufficient administrative permission","type":"OAuthException","code":200,"fbtrace_id":"XXXXXXXXX"}}
现在我的问题是我可以从哪里允许我的应用程序获得这些权限,因为我允许的地方都没有看到这些名称(publish_to_groups
、manage_pages
和 publish_pages
等)如上图所示。
注意:我现在创建的所有内容和代码,所以我需要使用新发布的解决方案 API 3.1.
更新:
我的朋友告诉我允许所有权限让我的代码工作,如下面的屏幕截图所示,但我无法在我的应用程序中查看这些权限。我需要所有这些。如何获得它们?
在我看来,您使用的是用户访问令牌。 要获取页面访问令牌,您应该调用端点:
https://graph.facebook.com/v3.1/{user-id or me}/accounts
获取页面列表和每个页面的访问令牌。
或者:
https://graph.facebook.com/v3.1/{page-id}?fields=access_token
如果您已经知道要访问的页面 post。
获得页面访问令牌后,您可以调用 feed
端点。
看看这里: https://developers.facebook.com/docs/pages/access-tokens
我尝试了很多东西,然后我在 Facebook 开发者指南上发现,在新的更新之后,如果应用程序上线,没有人可以获得以下所有显示的权限。要在您的应用上线后获得所有这些权限,您必须申请权限以进行审查,否则您可以在开发模式下免费获得所有权限但它只对您有效。
如您所知,要获得您的应用程序中的所有权限供您自己使用,您无需审查您的应用程序或任何其他内容即可获得它。您可以在下面看到一个应用程序的常规设置。
您只需关闭实时模式,将您的应用程序置于开发模式,如下图和上方的屏幕截图所示。
完成此操作后,只需转到 Graph API Explorer and click "Get Token" button then select "Get User Access Token" and here you will get the pop up as shown in the first screenshot of this Answer where you can select your desired scopes and click "Get Access Token". It will raise a POPUP where it will need your permission to allow and then it will return you the Access Token. (You Can Extend Your Access Token To 60 Days)
注意:此令牌将 post 在您的页面上仅对您可见,因为您的应用未上线,因此您的应用所做的每个 activity 仅供您使用.