2013-07-11 64 views
2

您好,我正在開發Salesforce中的應用程序,以訪問例如Google AdWords的AdWords報告數據。 ADGROUP_PERFORMANCE_REPORT。我正在發送http post請求到https://adwords.google.com/api/adwords/reportdownload/v201302,並且我正在使用apex(salesforce中的java語言),這是我的要求。如何在salesforce中獲取google adwords報告?

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> 

但是我的登錄ID和密碼是正確的。我做錯了什麼可以幫助任何人!

回答

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> 

填充所有需要的值*****。

相關問題