2

嗨,我正在 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>&lt;null&gt;</trigger><fieldPath></fieldPath></ApiError></reportDownloadError>

但是我的登录名和密码是正确的。我做错了什么可以请任何人帮忙!

4

1 回答 1

0

检查您的应用程序的配置。你必须有这样的东西:

<AdWordsApi>
    <add key="MaskCredentials" value="true" />
    <add key="EnableGzipCompression" value="true" />
    <add key="ProxyServer" value="" />
    <add key="ProxyUser" value="" />
    <add key="ProxyPassword" value="" />
    <add key="ProxyDomain" value="" />
    <add key="UserAgent" value="*******" />
    <add key="DeveloperToken" value="*******" />
    <add key="ClientCustomerId" value="*******" />
    <add key="SkipReportHeader" value="false" />
    <add key="SkipReportSummary" value="false" />
    <add key="OAuth2ClientId" value="*******" />
    <add key="OAuth2ClientSecret" value="*******" />
    <add key="OAuth2Mode" value="APPLICATION" />
    <add key="OAuth2RefreshToken" value="1/*******" />
</AdWordsApi>

填写所有必需的值 *****。

于 2015-09-11T07:23:15.980 回答