简体   繁体   English

Facebook Marketing API帐户

[英]Facebook Marketing API adaccounts

I'm having some trouble with the Facebook Marketing API. 我在使用Facebook Marketing API时遇到了一些麻烦。 I need to read all the active campaings the current user has, in all of his ad accounts. 我需要阅读当前用户在其所有广告帐户中拥有的所有活动广告。 So, the first step is to read all the ad accounts. 因此,第一步是读取所有广告帐户。

First, I tried what the documentation says: 首先,我尝试了文档中所说的内容:

// Add to header of your file
use FacebookAds\Object\AdUser;

// Add after Api::init()
$me = new AdUser('me');
$my_adaccount = $me->getAdAccounts()->current();

But the AdUser.php file doesn't exists in the SDK. 但是SDK中不存在AdUser.php文件。

So, I tried doing a request to the endpoint /me/adaccounts 因此,我尝试对端点/ me / adaccounts进行请求

$fb = new Facebook([
    'app_id'     => AppId,
    'app_secret' => AppSecret,
]);

$response = $fb->get('/me/adaccounts', Token);

This throws an error saying I'm using a deprecated version of the Marketing API (but I'm using the 3.2!!). 这会引发一个错误,说我正在使用过时的Marketing API版本(但我正在使用3.2 !!)。 I also tried 我也试过

$response = $fb->get('me?fields=adaccounts', Token);

And got the same error. 并得到了相同的错误。 Can anyone help me find another way?? 谁能帮我找到另一种方式?

PS: English is not my first language, sorry about that... PS:英语不是我的母语,对此感到抱歉。

I had the same problem. 我有同样的问题。 Check this solution! 检查此解决方案!

    // Add after Api::init()

    $user = new \FacebookAds\Object\User();
    $user->setId($userID);
    $user->setApi($api);

    $accounts = $user->getAdAccounts(array(\FacebookAds\Object\Fields\AdFields::NAME));
    foreach ($accounts as $acc) {
      echo $acc->name;
    }

Using php SDK 使用PHP SDK

try {
  // Returns a `Facebook\FacebookResponse` object
  $response = $fb->get(
    '/<USER_ID>/adaccounts',
    '{access-token}'
  );
} catch(Facebook\Exceptions\FacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}

You can check campaigns using insights api. 您可以使用见解API查看广告系列。 Type following line in explorer and see the magic 在资源管理器中输入以下行并查看魔术

me/campaigns?fields=id,name,status,effective_status 我/广告系列?fields = id,名称,状态,有效状态

This will give you list of 25 campaigns and you can read their status & effective status. 这将为您提供25个广告系列的列表,您可以阅读它们的状态和有效状态。 You can use php sdk syntax call above api url and read response. 您可以在api网址上方使用php sdk语法调用并读取响应。

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

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