嗨,我正在 Salesforce 中开发应用程序,用于访问例如 ADGROUP_PERFORMANCE_REPORT 的 google adwords 报告数据。我正在向https://adwords.google.com/api/adwords/reportdownload/v201302发送 http 发布请求,并且我正在使用 apex(salesforce 中的类似 java 的语言)是我的请求。
Http h = new Http();
HttpRequest req = new HttpRequest();
GoogleAuthorization auth=new GoogleAuthorization();
req.setHeader('Authorization', 'GoogleLogin ' + auth.token);
req.setHeader('UserAgent', 'XXXXX');
req.setHeader('developerToken','XXXXXXXX');
req.setHeader('clientCustomerId','XXXXXXXX');
req.setEndPoint('https://adwords.google.com/api/adwords/reportdownload/v201302');
req.setHeader('Content-Type', 'application/x-www-form-urlencoded');
req.setMethod('POST');
string xml='<reportDefinition xmlns="https://adwords.google.com/api/adwords/cm/v201302">'+
'<selector>'+
'<fields>CampaignId</fields>'+
'<fields>Id</fields>'+
'<fields>Impressions</fields>'+
'<fields>Clicks</fields>'+
'<fields>Cost</fields>'+
'<predicates>'+
'<field>Status</field>'+
'<operator>IN</operator>'+
'<values>ENABLED</values>'+
'<values>PAUSED</values>'+
'</predicates>'+
'</selector>'+
'<reportName>Custom Adgroup Performance Report</reportName>'+
'<reportType>ADGROUP_PERFORMANCE_REPORT</reportType>'+
'<dateRangeType>LAST_7_DAYS</dateRangeType>'+
'<downloadFormat>XML</downloadFormat>'+
'</reportDefinition>';
req.setBody('__rdxml='+EncodingUtil.urlEncode(xml, 'UTF-8'));
HttpResponse res=h.send(req);
请求后,我得到了 AuthenticationError System.HttpResponse[Status=Bad Request,StatusCode=400]。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><reportDownloadError><ApiError><type>AuthenticationError.USER_ID_INVALID</type><trigger><null></trigger><fieldPath></fieldPath></ApiError></reportDownloadError>
但是我的登录名和密码是正确的。我做错了什么可以请任何人帮忙!