简体   繁体   English

如何在Graph API上从facebook Ads获取数据?

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

I am new to PHP and facebook API'S 我是PHP和Facebook API的新手

I am trying to get data from my ads account on faceobook using PHP 我正在尝试使用PHP从Faceobook上的广告帐户中获取数据

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 ? 首先-我不知道我是否必须拥有facebook应用程序才能从我的个人广告帐户中获取数据?

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 但是,当我尝试这样的获取请求时: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: 您需要将其作为url参数添加到url的末尾:

"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. 但是,我认为从代码中您将获得一个应用程序访问令牌,并且需要页面访问令牌或用户访问令牌才能获取与您的Facebook页面相关的广告。

Please refer to https://developers.facebook.com/docs/facebook-login/access-tokens/ for more information. 请参阅https://developers.facebook.com/docs/facebook-login/access-tokens/了解更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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