ads.getCampaignStats - 管理广告需要扩展权限ads_management和参与的API密钥

时间:2011-10-03 08:35:19

标签: facebook facebook-graph-api advertising

我正在尝试使用ads.getCampaignStats图表api调用从我的广告系列中获取一些统计信息但我收到此错误:

"error_code": 294,
    "error_msg": "Managing advertisements requires the extended permission ads_management, and a participating API key"

我正在使用facebook php api v3.1.1。这是执行登录身份验证的代码:

define('FACEBOOK_APP_ID', 'xxxxx');
define('FACEBOOK_SECRET', 'xxxxxxxxxxxxx');

// Remember to copy files from the SDK's src/ directory to a
// directory in your application on the server, such as php-sdk/
require_once('src/facebook.php');

$config = array(
'appId' => FACEBOOK_APP_ID,
'secret' => FACEBOOK_SECRET,
);

$facebook = new Facebook($config);
$user_id = $facebook->getUser();
if($user_id) {
try {
$result = $facebook->api(array(
"method"        => "ads.getCampaignStats",
"account_id"    => "xxxxxx",
"ext_perm"      => "ads_management",
"campaign_ids"  => json_encode(array("xxxxxxxxxx")),
"time_ranges"   => "[\"time_start\":1284102000,\"time_stop\":1284447600]"));
var_dump($result);
} catch(FacebookApiException $e) {
// If the user is logged out, you can have a 
// user ID even though the access token is invalid.
// In this case, we'll get an exception, so we'll
// just ask the user to login again here.
$login_url = $facebook->getLoginUrl(array(
                'scope' => 'ads_management')); 
echo 'Please <a href="' . $login_url . '">login.</a>';
error_log($e->getType());
error_log($e->getMessage());
}   
} else {
     // No user, print a link for the user to login
  $login_url = $facebook->getLoginUrl(array(
                'scope' => 'ads_management'
        ));
  echo 'Please <a href="' . $login_url . '">login.</a>';

}

如果我在下面的链接上使用facebook提供的测试控制台,同样的事情就会发生:ads.getCampaignStats - test console

有什么想法吗?我做错了什么?任何帮助都将非常感激。

感谢所有人。

1 个答案:

答案 0 :(得分:0)

您必须为拥有广告API访问权限的帐户授予权限。