我试图获取广告系列的每日费用。 我使用此文档https://developers.google.com/adwords/api/docs/guides/reporting
我也在使用php和Yii2。我有:
客户客户ID
客户端ID
访问令牌
client_secret
refresh_token
当我获得广告系列名称和ID时,那些客户端客户ID,客户端ID,client_secret 就足够了,我可以毫无问题地获得广告系列,但是当我尝试获取报告时,会出现错误< / p>
string(581) "HTTP/1.1 400 Bad Request
Content-Type: text/xml
Date: Mon, 22 May 2017 10:31:52 GMT
Expires: Mon, 22 May 2017 10:31:52 GMT
Cache-Control: private, max-age=0
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
Accept-Ranges: none
Vary: Accept-Encoding
Transfer-Encoding: chunked
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><reportDownloadError><ApiError><type>ReportDownloadError.INVALID_PARAMETER</type><trigger>Missing client information</trigger><fieldPath></fieldPath></ApiError></reportDownloadError>"
也许我用curl错误地发帖请求,因为我能够毫无错误地获得广告系列。 这是我的代码
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://adwords.google.com/api/adwords/reportdownload/v201702");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_HEADER,1);
$XML= <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<reportDefinition xmlns="https://adwords.google.com/api/adwords/cm/v201702">
<selector>
<fields>CampaignId</fields>
<fields>AdGroupId</fields>
<fields>Impressions</fields>
<fields>Clicks</fields>
<fields>Cost</fields>
<predicates>
<field>AdGroupStatus</field>
<operator>IN</operator>
<values>ENABLED</values>
<values>PAUSED</values>
</predicates>
</selector>
<reportName>Custom Adgroup Performance Report</reportName>
<reportType>ADGROUP_PERFORMANCE_REPORT</reportType>
<dateRangeType>TODAY</dateRangeType>
<downloadFormat>CSV</downloadFormat>
</reportDefinition>
XML;
$headers = array("Content-Type:multipart/form-data",
"Authorization"=> "Bearer my_access_token",
"developerToken" => "my_developer_token",
"clientCustomerId"=> 111-111-1111, // test account
);
$postfields = array("__rdxml" =>$XML );
curl_setopt($ch, CURLOPT_HTTPHEADER , $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
echo "<pre>";
var_dump($server_output);
echo "</pre>";
curl_close ($ch);
答案 0 :(得分:0)
事实证明我生成了错误的访问令牌。当我按照此处所述生成https://developers.google.com/identity/protocols/OAuth2WebServer#incrementalAuth时 一切顺利。