2014-07-22 105 views
0

我想獲取谷歌anatytics報告數據到salesforce。我有一個auth_token,當我嘗試調用API報告我得到以下錯誤:谷歌分析報告整合問題與銷售隊伍

{"error": 
    {"errors": 
     [ 
      { 
       "domain": "global", 
       "reason": "required", 
       "message": "Required parameter: metrics", 
       "locationType": "parameter", 
       "location": "metrics" 
      }, 
      { 
       "domain": "global", 
       "reason": "required", 
       "message": "Required parameter: start-date", 
       "locationType": "parameter", 
       "location": "start-date" 
      } 
     ], 
     "code": 400, 
     "message": "Required parameter: metrics" 
    } 
} 400 

我的代碼是:

public void fetchReportsTest(String accT){ 

    http h = new Http(); 
    Httprequest req = new HttpRequest(); 
    HttpResponse res = new HttpResponse(); 
    Date startDate = Date.today(); 
    Date endDate = Date.today().addMonths(1); 
    //req.setEndpoint('https://www.googleapis.com/analytics/v3/data/realtime?ids=ga%3A272183&metrics=ga%3uniqueEvent&dimensions=ga%3eventAction&key='+accT); 
    req.setEndpoint('https://www.googleapis.com/analytics/v3/data/ga?ids=ga:56442671&star-date=2014-07-01&end-date=2014-07-31&matrics=ga:eventValue'); 
    req.setMethod('GET'); 
    req.setHeader('Authorization','Bearer '+accT); 
    //req.setHeader('ContentType','application/X-JavaScript-User-Agen'); 
    req.setHeader('ContentType','application/x-www-form-urlencoded'); 
    res = h.send(req); 
    reportData = res.getBody() +' '+ res.getStatusCode(); 
    system.debug('===reportData==='+reportData); 
} 

請告訴我,如果我錯過了什麼。

回答