When i use this code:
当我使用这个代码:
<?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
I get error: Fatal error: Uncaught FacebookAds\Http\Exception\AuthorizationException: (#190) This method must be called with a Page Access Token in ...
我得到错误:致命错误:未捕获的FacebookAds\Http\Exception AuthorizationException:(#190)这个方法必须在…
But when I put page_access_token in place of app_access_token (from https://developers.facebook.com/tools/explorer) i get error: Uncaught FacebookAds\Http\Exception\AuthorizationException: Invalid appsecret_proof provided in the API argument in ...
. When i remove line:
但是当我把page_access_token代替app_access_token(https://developers.facebook.com/tools/explorer)我得到错误:未捕获FacebookAds \ Http \例外\ AuthorizationException:无效appsecret_proof .... API提供的论据当我删除线:
2 个解决方案
#1
5
Seems you are working on lead-gen forms that are meant for pages only. Your profile must have admin/developer role assigned. You definitely seem to have missed/copied incorrect value for one of the below. Below details are copied from https://developers.facebook.com/docs/marketing-api/guides/lead-ads/retrieving for quicker understanding
看来你在做的是只针对页面的引导源表单。您的概要文件必须分配管理/开发人员角色。您显然已经错过/复制了下面其中一个错误的值。下面的详细信息是从https://developers.facebook.com/docs/marketing-api/guides/lead-ads/retrieve拷贝的,以便更快地理解
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.
使用页面访问令牌,即页面管理员对页面的访问令牌。页面访问令牌还允许您读取广告特定的字段,如ad_id、战役_id等,如果您至少对与领先广告关联的广告帐户具有广告商级别的权限的话。
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.
使用属于页面管理员的用户访问令牌。要访问所有的前置数据和ad级数据,访问令牌应该具有manage_pages和ads_management作用域。
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.
您可以使用页面角色管理用户权限。此外,如果需要允许页面上具有非管理员角色的用户进行引线下载,可以使用leadgen_whitelisted_users端点对其进行白名单。
#2
0
The other answers are not showing how to actually send a Page Access Token instead of an App Access Token or User Access Token.
其他的答案没有显示如何实际发送页面访问令牌而不是应用程序访问令牌或用户访问令牌。
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
#1
5
Seems you are working on lead-gen forms that are meant for pages only. Your profile must have admin/developer role assigned. You definitely seem to have missed/copied incorrect value for one of the below. Below details are copied from https://developers.facebook.com/docs/marketing-api/guides/lead-ads/retrieving for quicker understanding
看来你在做的是只针对页面的引导源表单。您的概要文件必须分配管理/开发人员角色。您显然已经错过/复制了下面其中一个错误的值。下面的详细信息是从https://developers.facebook.com/docs/marketing-api/guides/lead-ads/retrieve拷贝的,以便更快地理解
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.
使用页面访问令牌,即页面管理员对页面的访问令牌。页面访问令牌还允许您读取广告特定的字段,如ad_id、战役_id等,如果您至少对与领先广告关联的广告帐户具有广告商级别的权限的话。
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.
使用属于页面管理员的用户访问令牌。要访问所有的前置数据和ad级数据,访问令牌应该具有manage_pages和ads_management作用域。
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.
您可以使用页面角色管理用户权限。此外,如果需要允许页面上具有非管理员角色的用户进行引线下载,可以使用leadgen_whitelisted_users端点对其进行白名单。
#2
0
The other answers are not showing how to actually send a Page Access Token instead of an App Access Token or User Access Token.
其他的答案没有显示如何实际发送页面访问令牌而不是应用程序访问令牌或用户访问令牌。
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