2

我是 PHP 和 facebook API 的新手

我正在尝试使用 PHP 从我在 Facebook 上的广告帐户中获取数据

我只想知道每个广告花了多少钱

首先 - 我不明白我是否必须拥有 facebook 应用程序才能从我的个人广告帐户中获取数据?

我假设是的,所以我现在创建了一个..,我得到了这样的访问令牌:

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

但是当我尝试这样的获取请求时:https://graph.facebook.com/act_[my_account_number]/adgroups

我得到一个前提例外,告诉我

需要访问令牌来请求他的资源

但是我在哪里放置访问令牌?

4

1 回答 1

0

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.

于 2014-02-21T13:06:29.120 回答