如何与管理员访问的用户,同时创建广告帐户facebook营销api


How to aduser with admin access while creating ad account 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);