为什么ga:clientId维请求在使用python3谷歌分析v4时返回空数组?

问题描述 投票:1回答:1

[目前正在尝试通过python代码从Google Analytics(分析)获取clientId:

def get_report(analytics):
    return analytics.reports().batchGet(
        body={
            "reportRequests": [
                {
                    "viewId": VIEW_ID,
                    "dateRanges": [{"startDate": "7daysAgo", "endDate": "today"}],
                    "dimensions": [{"name": "ga:pagePath"}, {"name": "ga:clientId"}],
                    "metrics": [{"expression": "ga:pageViews"}, {"expression": "ga:sessions"},
                                {"expression": "ga:avgTimeOnPage"}]
                }]
        }
    ).execute()

此代码返回空数组,如果我删除:

{"name": "ga:clientId"}

它工作正常,并返回所有数据。同样使用Java,我可以通过以下方式获得clientID号:

Dimension clientId = new Dimension().setName("ga:clientId"); 

ReportRequest request = new ReportRequest()
        .setViewId(VIEW_ID)
        .setDateRanges(Arrays.asList(dateRange))
        .setMetrics(lstMetrics)
        .setDimensions(lstDim);

    ArrayList<ReportRequest> requests = new ArrayList<ReportRequest>();
    requests.add(request);

    // Create the GetReportsRequest object.
    GetReportsRequest getReport = new GetReportsRequest()
        .setReportRequests(requests);

    // Call the batchGet method.
    GetReportsResponse response = service.reports().batchGet(getReport).execute();

    // Return the response.
    return response;

但是python无法产生相同的数据响应。

[目前正在尝试通过python代码从Google Analytics(分析)获取clientId:def get_report(analytics):return analytics.reports()。batchGet(body = {“ reportRequests”:[...

python-3.x google-analytics google-api google-analytics-api clientid
1个回答
0
投票

事实证明,谷歌分析api v3实际上可以按照我在上面的问题中显示的方式与python脚本配合使用。在google页面上找不到有关此文档:(

© www.soinside.com 2019 - 2024. All rights reserved.