Bing Ads api仅返回我的请求中第一个关键字的数据

时间:2016-06-09 17:46:17

标签: php bing-api

我希望获得大型关键字数据集的cpc和其他数据。但是,当我将请求发送到api时,我只收到Keywords数组中第一个关键字的数据。您将从下面的第二张图片中注意到EstimatedBids数据对象的单词送货,比萨饼,保险和律师都是空的。比方说,如果我把关键字“律师”放在数组中,我将获得律师的数据,其余的则没有。

我的代码:

$keywords = array('flowers', 'delivery', 'pizza', 'insurance', 'lawyer'); // example array for this question
$proxy = ClientProxy::ConstructWithAccountAndCustomerId($wsdl, null, null, $DeveloperToken, $AccountId, $CustomerId, $AccessToken); //no $UserName & $Password

$matchTypes = array (MatchType::Exact);
$keywordAndMatchTypes = array();
foreach ($keywords as $keyword) {
        $keywordAndMatchType = new KeywordAndMatchType();
        $keywordAndMatchType->KeywordText = $keyword;
        $keywordAndMatchType->MatchTypes = $matchTypes;
        array_push($keywordAndMatchTypes, $keywordAndMatchType);
}

$request_cpc = new GetEstimatedBidByKeywordsRequest();
$request_cpc->Keywords = $keywordAndMatchTypes;

$response_cpc = $proxy->GetService()->GetEstimatedBidByKeywords($request_cpc)->KeywordEstimatedBids;

我的要求:

Bing Ads API Request

我的回复:

Bing Ads API Response

需要更改哪些内容才能获取所有关键字的数据?提前感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

对于任何未来的googlers,我通过在$matchTypes循环中实例化foreach数组来解决我的问题。换句话说,我改变了这个旧代码:

$matchTypes = array (MatchType::Exact);
$keywordAndMatchTypes = array();
foreach ($keywords as $keyword) {
        $keywordAndMatchType = new KeywordAndMatchType();
        $keywordAndMatchType->KeywordText = $keyword;
        $keywordAndMatchType->MatchTypes = $matchTypes;
        array_push($keywordAndMatchTypes, $keywordAndMatchType);
}

进入这个新代码:

$keywordAndMatchTypes = array();
foreach ($keywords as $keyword) {
        $keywordAndMatchType = new KeywordAndMatchType();
        $matchTypes = array (MatchType::Exact);
        $keywordAndMatchType->KeywordText = $keyword;
        $keywordAndMatchType->MatchTypes = $matchTypes;
        array_push($keywordAndMatchTypes, $keywordAndMatchType);
}

由于某种原因,每次都必须实例化$matchTypes数组。