php - 如何在创建广告帐户 facebook marketing api 时使用管理员权限

标签 php facebook-graph-api facebook-marketing-api

我正在尝试使用以下代码通过 Facebook 营销和图形 API 在 Facebook 业务管理器中创建广告帐户。

$attachment =  array('access_token'      => $this->accessToken,
                        'name'           => $associative_arr['name'],
                        'currency'       => $associative_arr['currency'],
                        'timezone_id'    => $associative_arr['timezone_id'],
                        'end_advertiser' => $this->mybusinessId,
                        'media_agency'   => 'NONE',
                        'partner'        => 'NONE',
                        'access_type'    => 'OWNER',
                        'permitted_roles' => 'ADMIN'
                        //'user_role'        => '1001'
                        );

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/'.$this->apiVersion.'/'.$this->mybusinessId.'/adaccount');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  //to suppress the curl output 
$result = curl_exec($ch);
$dcde = json_decode($result);
curl_close ($ch);

它成功创建了广告帐户,但没有将我添加为具有管理权限的用户。

谁能给我建议是什么原因?

最佳答案

创建广告帐户后,您需要再次调用以添加具有所需权限的用户。

$attachment =  array(
    'access_token' => $this->accessToken,
    'business' => '<business_id>',
    'user' => '<user_id>',
    'role' => 'ADMIN'
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/'.$this->apiVersion.'/act_<AD_ACCOUNT_ID>/userpermissions');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  //to suppress the curl output 
$result = curl_exec($ch);
$dcde = json_decode($result);
curl_close ($ch);

关于php - 如何在创建广告帐户 facebook marketing api 时使用管理员权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40128230/

相关文章:

php - QuickSort:当 Pivot 交换位置时无法理解部分

php - 显示串联的sql数据

PHPStorm + PHPdoc - 我可以键入提示单个数组元素吗?

android - 登录到 facebook 一个按钮来打开一个新的 Activity

jquery - jQuery getJSON 之后获取数据

node.js - Facebook Ads API 已弃用,请更新至最新版本 v3.0

python - Facebook python 营销 API AttributeError

php - 将 2 个文件读入关联数组

facebook-graph-api - Facebook FQL 查询和多查询的限制是什么(多查询的最大数量和速率限制)

facebook - 按任何给定字段过滤 Facebook 图表结果