【发布时间】:2014-02-24 02:44:58
【问题描述】:
我正在尝试构建一个“尽可能简单”的例程来检索 AdWords 广告系列名称。
但是,我收到此错误消息
AuthenticationError.LOGIN_COOKIE_REQUIRED @ ;触发器:'
'
每当我第一次运行以下 PHP 脚本时。
后续运行可以正常运行几个小时,直到我再次收到错误(我相信引用的 cookie 再次过期)。
这个 cookie 是关于什么的?有人能指出发生了什么以及如何解决它吗?
<?php
$refreshToken=/* omitted */;
$clientId=/* omitted */;
$clientSecret=/* omitted */;
$clientCustomerId=/* omitted */;
$developerToken=/* omitted */;
$ch=curl_init('https://accounts.google.com/o/oauth2/token');
curl_setopt($ch,CURLOPT_HEADER,false);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_CUSTOMREQUEST,'POST');
curl_setopt($ch,CURLOPT_POSTFIELDS,http_build_query(array(
'refresh_token'=>$refreshToken,
'client_id'=>$clientId,
'client_secret'=>$clientSecret,
'grant_type'=>'refresh_token',
)));
$json=curl_exec($ch);
curl_close($ch);
$object=json_decode($json);
$accessToken=$object->access_token;
$namespace='https://adwords.google.com/api/adwords/cm/v201309';
$soapClient=new SoapClient($namespace.'/CampaignService?wsdl',array(
'features'=>SOAP_SINGLE_ELEMENT_ARRAYS,
'encoding'=>'utf-8',
'stream_context'=>stream_context_create(array(
'http'=>array(
'header'=>'Authorization : Bearer '.$accessToken,
),
)),
));
$soapClient->__setSoapHeaders(new SoapHeader($namespace,'RequestHeader',array(
'clientCustomerId'=>$clientCustomerId,
'developerToken'=>$developerToken,
'userAgent'=>'TestApp',
'validateOnly'=>false,
'partialFailure'=>false,
)));
try
{
$result=$soapClient->get(array(
'serviceSelector'=>array(
'fields'=>array('Name'),
),
));
}
catch (SoapFault $e)
{
$result=$e->getMessage();
}
var_dump($result);
【问题讨论】:
-
我怀疑这与 WSDL 缓存有关:如果我在 SoapClient 选项中设置了 'cache_wsdl' => WSDL_CACHE_NONE,那么我总是会收到错误消息。
标签: php authentication cookies google-ads-api