简体   繁体   中英

How to aduser with admin access while creating ad account facebook marketing api

I am trying to create ad account in Facebook business manager via Facebook marketing and graph API using following code.

$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);

It successfully creates ad account but does not add me as a user in people with administrative access.

Can anyone give me suggestion what can be the reason?

Once the ad account is created, you'll need to make another call which will add the user with the required permissions.

$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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM