位置搜索参数

时间:2018-07-03 11:35:42

标签: php google-adwords

我一直在尝试通过API从“关键字规划工具”中获取选项“批量搜索”,并且在尝试将Location Search Parameter传递给服务调用时遇到错误。这是代码:

    $service = new AdwordsServices();
    $query = $service->get($session, TargetingIdeaService::class);

    $words = ['Hotel 1', 'Hotel 3', 'Hotels'];

    $selector = new TargetingIdeaSelector();
    $selector->setRequestType(RequestType::STATS);
    $selector->setIdeaType(IdeaType::KEYWORD);
    $selector->setRequestedAttributeTypes([
        AttributeType::KEYWORD_TEXT,
        AttributeType::SEARCH_VOLUME,
        AttributeType::TARGETED_MONTHLY_SEARCHES
    ]);




    $relatedToQuerySearchParameter = new RelatedToQuerySearchParameter();
    $relatedToQuerySearchParameter->setQueries($words);
    $searchParameters[] = $relatedToQuerySearchParameter;

    $loc = array();
    $location = new Location();
    $location->setId(2840); // USA
    $loc[]=$location;
    $locationTargetParameter = new LocationSearchParameter();
    $locationTargetParameter->setLocations($loc);
    $searchParameters[] = $locationTargetParameter;



    $selector->setSearchParameters($searchParameters);
    $selector->setPaging(new Paging(0, 500));

    $page = $query->get($selector);
    $entries = $page->getEntries();

    if ($entries) {
        foreach ($entries as $entry) {

            $data = MapEntries::toAssociativeArray($entry->getData());
            $keyword = $data[AttributeType::KEYWORD_TEXT]->getValue();
            $searchVolume = ($data[AttributeType::SEARCH_VOLUME]->getValue() !== null) ? $data[AttributeType::SEARCH_VOLUME]->getValue() : 0;
            $monthly = ($data[AttributeType::TARGETED_MONTHLY_SEARCHES]->getValue() !== null) ? $data[AttributeType::TARGETED_MONTHLY_SEARCHES]->getValue() : 0;
            dd($monthly);
        }
    }

错误:

  

SoapFault:解组错误:cvc-type.2:类型定义不能为元素ns1:searchParameters的抽象。

     在/../../../../vendor/googleads/googleads-php-中的

  lib / src / Google / AdsApi / Common / AdsSoapClient.php:152    148 | $ function_name,   149 | $参数,   150 | $ options,   151 | $ input_headers,   152 | $ output_headers   153 | );   154 | $ this-> processResponse($ function_name);   155 | }捕获(SoapFault $ soapFault){   156 | $ this-> processResponse($ function_name,$ soapFault);

它返回不带 $ locationTargetParameter 的数据,如下所示:

    array:12 [
  0 => Google\AdsApi\AdWords\v201802\o\MonthlySearchVolume {#683
    #year: 2018
    #month: 5
    #count: 6600
  }
  1 => Google\AdsApi\AdWords\v201802\o\MonthlySearchVolume {#681
    #year: 2018
    #month: 4
    #count: 6600
  }
  2 => Google\AdsApi\AdWords\v201802\o\MonthlySearchVolume {#682
    #year: 2018
    #month: 3
    #count: 6600
  }
  3 => Google\AdsApi\AdWords\v201802\o\MonthlySearchVolume {#679
    #year: 2018
    #month: 2
    #count: 5400
  }
  4 => Google\AdsApi\AdWords\v201802\o\MonthlySearchVolume {#680
    #year: 2018
    #month: 1
    #count: 5400
  }
  5 => Google\AdsApi\AdWords\v201802\o\MonthlySearchVolume {#689
    #year: 2017
    #month: 12
    #count: 3600
  }
  6 => Google\AdsApi\AdWords\v201802\o\MonthlySearchVolume {#688
    #year: 2017
    #month: 11
    #count: 4400
  }
  7 => Google\AdsApi\AdWords\v201802\o\MonthlySearchVolume {#687
    #year: 2017
    #month: 10
    #count: 4400
  }
  8 => Google\AdsApi\AdWords\v201802\o\MonthlySearchVolume {#686
    #year: 2017
    #month: 9
    #count: 4400
  }
  9 => Google\AdsApi\AdWords\v201802\o\MonthlySearchVolume {#701
    #year: 2017
    #month: 8
    #count: 4400
  }
  10 => Google\AdsApi\AdWords\v201802\o\MonthlySearchVolume {#699
    #year: 2017
    #month: 7
    #count: 5400
  }
  11 => Google\AdsApi\AdWords\v201802\o\MonthlySearchVolume {#690
    #year: 2017
    #month: 6
    #count: 5400
  }
]

0 个答案:

没有答案