使用带有Python的Google adwords API时出现authenticationerror.login_cookie_required错误

时间:2011-11-13 21:21:16

标签: python soap google-adwords

我正在尝试使用python来使用一些adwords soap API,我能够获取身份验证令牌但是当我尝试发出get请求时,我收到了authenticationerror.login_cookie_required错误。有什么想法吗?

from suds.client import Client

auth_data = {'accountType':'GOOGLE', 'Email':'xxx@xxx.com', 'Passwd':'xxxxxxxx', 'service':'adwords', 'source':'xxxxxxxxxx'}
auth_data = urllib.urlencode(auth_data)
auth_request = urllib2.Request('https://www.google.com/accounts/ClientLogin', auth_data)
auth_response = urllib2.urlopen(auth_request)
auth_response = auth_response.read()
split = auth_response.split('=')
auth_token = split[len(split)-1]

url = 'https://adwords-sandbox.google.com/api/adwords/cm/v201109/CampaignService?wsdl'
client = Client(url)
authToken = auth_token
developerToken = 'xxx@xxx.com++NZD'
userAgent = 'jameslin-python'
client.set_options(soapheaders=(authToken,developerToken,userAgent))
client.service.get()

2 个答案:

答案 0 :(得分:0)

您是否尝试过使用适用于AdWords API的Python客户端库? http://code.google.com/p/google-api-ads-python/

答案 1 :(得分:0)

authToken不是SOAP标头。 RequestHeader是soap标头,authToken是该标头的成员。有关详细信息,请参阅http://code.google.com/apis/adwords/docs/headers.htmlhttp://code.google.com/apis/adwords/docs/#soap

我还想指出,AdWords API官方论坛是http://groups.google.com/group/adwords-api,我们会定期回答有关AdWords API的问题。如果您有任何后续问题,请随时在官方论坛上询问。

干杯, Anash