FB App 必须使用页面访问令牌调用此方法

FB App This method must be called with a Page Access Token

当我使用这段代码时:

<?php 

require_once "vendor/autoload.php";

$config = ...;

use FacebookAds\Api;
use FacebookAds\Object\Page;

Api::init(
    $config['facebook']['app_id'], //APP_ID
    $config['facebook']['app_secret'], //APP SECRET
    $config['facebook']['app_access_token'] //Token generated by https://developers.facebook.com/tools/explorer for app
);

$page = new Page($config['facebook']['page_id']);
$leadgen_forms = $page->getLeadgenForms(); //heres an error

我收到错误: Fatal error: Uncaught FacebookAds\Http\Exception\AuthorizationException: (#190) This method must be called with a Page Access Token in ...

但是当我用 page_access_token 代替 app_access_token(来自 https://developers.facebook.com/tools/explorer)时,我得到错误:Uncaught FacebookAds\Http\Exception\AuthorizationException: Invalid appsecret_proof provided in the API argument in ...。当我删除行时:

您似乎正在处理仅用于页面的 lead-gen 表单。您的个人资料必须分配有 admin/developer 角色。对于以下其中一项,您肯定 missed/copied 的值不正确。 以下详细信息是从 https://developers.facebook.com/docs/marketing-api/guides/lead-ads/retrieving 复制的,以便更快地理解

One can read leads or real-time updates by:

Using a Page Access Token, i.e. the Page admin's access token for the page. Page access token also allows you to read ad specific fields such as ad_id, campaign_id, etc., if you have atleast advertiser level permissions on the ad account associated with the lead ad.

Using User Access Token belonging to the page admin. To access all of the lead data and the ad level data, the access token should have manage_pages and ads_management scope.

You can manage user rights with Page roles. In addition, if you need to allow leads download for user with non-admin role on the page, you can whitelist it with leadgen_whitelisted_users endpoint.

其他答案没有说明如何实际发送页面访问令牌而不是应用访问令牌或用户访问令牌。

require_once "vendor/autoload.php";

$config = ...;

use FacebookAds\Api;
use FacebookAds\Object\Page;
use FacebookAds\Session;

$api = Api::init(
    $config['facebook']['app_id'], //APP_ID
    $config['facebook']['app_secret'], //APP SECRET
    $config['facebook']['app_access_token'] //Token generated by https://developers.facebook.com/tools/explorer for app
);
$page_api = $api->getCopyWithSession(new Session(
    $config['facebook']['app_id'], //APP_ID
    $config['facebook']['app_secret'], //APP SECRET
    $page_access_token  // <-- You can get this by accessing 'me/accounts' w/ the initial API
));
$page = new Page($config['facebook']['page_id'], null, $page_api); // <-- use the api with the Page Access Token here
$leadgen_forms = $page->getLeadgenForms(); //heres an error