广告系列监控API获取摘要

时间:2013-07-09 15:44:03

标签: php foreach campaign-monitor

我正在使用广告系列监视器API并访问广告系列摘要。到目前为止,我有以下工作:

require_once '../../csrest_campaigns.php';

$auth = array('api_key' => 'xxxxxxxxxxxxxxxxxxxxxxxxx');
$wrap = new CS_REST_Campaigns('xxxxxxxxxxxxxxxxxxxxxx', $auth);

$result = $wrap->get_summary();

echo "Result of GET /api/v3/campaigns/{id}/summary\n<br />";
if($result->was_successful()) {

    var_dump($result->response);

} else {
    echo 'Failed with code '.$result->http_status_code."\n<br /><pre>";
    var_dump($result->response);
}
echo '</pre>';

我想从上面提取某些数据,所以我添加了以下内容(替换var_dump):

foreach($result->response as $entry) { 
        echo $entry->Recipients;
        echo $entry->TotalOpened.'<br/>';
        echo $entry->Clicks.'<br/>';
        echo $entry->Unsubscribed.'<br/>';
        echo $entry->Bounced.'<br/>';
        echo $entry->UniqueOpened.'<br/>';
        echo $entry->SpamComplaints.'<br/>';
        echo $entry->WebVersionURL.'<br/>';
        echo $entry->WebVersionTextURL.'<br/>';
        echo $entry->WorldviewURL.'<br/>';
        echo $entry->Forwards.'<br/>';
        echo $entry->Likes.'<br/>';
        echo $entry->Mentions.'<br/>';
    }

这显示没有数据?谁能看到我哪里错了?

的var_dump:

stdClass Object
(
    [Recipients] => 5
    [TotalOpened] => 28
    [Clicks] => 2
    [Unsubscribed] => 0
    [Bounced] => 0
    [UniqueOpened] => 4
    [SpamComplaints] => 0
    [WebVersionURL] => http://xxxxxxxxxxxxxxxx
    [WebVersionTextURL] => http://xxxxxxxxxxxxxxxxxxx
    [WorldviewURL] => http://xxxxxxxxxxxxxxxxxxx
    [Forwards] => 0
    [Likes] => 0
    [Mentions] => 0
)   

1 个答案:

答案 0 :(得分:0)

请参阅stdClass object and foreach loops - campaign monitor api

我想你可能需要:

$campaigns = $result->response->Results;

然后:

foreach($campaigns as $s) {
    echo $s->Recipients . "\t" . $s->TotalOpened . "\n"; // etc.
}

大多数Campaign Monitor方法返回对象都有一个响应 - &gt;结果结构来获取一组中的各个项目(广告系列,列表,订阅者等)。正如您可能看到的那样,文档没有解释最后一步 - 它只是var_dump对象,尽管您可以通过检查它们来确定要做什么。确保在直接检查对象之前检查是否有任何包装器,但我发现你最终使用response-&gt;结果来获取数据数组。 皮特