简体   繁体   中英

How to get data from facebook Ads on the Graph API?

I am new to PHP and facebook API'S

I am trying to get data from my ads account on faceobook using PHP

I just want to know how much $ every ads spent

First of all - I did not understand if I must have facebook app in order to get data from my personal ad account ?

I assumed yes so I created one now.., I am geting the acess token like this :

require_once("facebook.php");

  $config = array();
  $config['appId'] = 'myapp_id';
  $config['secret'] = 'myappsecret';
  $config['fileUpload'] = false; // optional

  $facebook = new Facebook($config);

  // Set a new app secret
$facebook->setApiSecret($config['secret']);

// If you do above, also set the app id
$facebook->setAppId( $config['appId']);

 $access_token = $facebook->getAccessToken();

But when I am trying a get request like this: https://graph.facebook.com/act_[my_account_number]/adgroups

I am getting a premisson exception that tell me

An access token is required to request his resource

But where do I put the access token ?

You need to add it at the end of the url as a url parameter:

"https://graph.facebook.com/act_[my_account_number]/adgroups" . "?access_token=" . $access_token

However, from the code I think you are getting an App Access Token, and you need a Page Access Token or a User Access Token to get the ads related to your Facebook Page.

Please refer to https://developers.facebook.com/docs/facebook-login/access-tokens/ for more information.

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