与salesforce的Google Analytic Report集成问题

时间:2014-07-22 13:18:58

标签: google-analytics salesforce

我正在尝试将google 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);
}

如果我遗漏了任何东西,请告诉我。

1 个答案:

答案 0 :(得分:0)

你有一个错字:

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&#39);

将其更正为指标