GA多渠道程序报告了Python错误

时间:2019-03-05 14:40:50

标签: python google-analytics-api

我已经能够成功使用reports().batchGet()

从G网站上提供的python示例中查询来自Google Analytics(分析)的数据

现在我必须对多渠道漏斗(mcf)进行同样的操作。

我在StackO或其他任何地方看到的所有内容都是调用service.data().mcf().get()。但是然后我得到了错误AttributeError: 'Resource' object has no attribute 'service'

我认为这是我建立请求的方式,但是使用Google apiclient的方式与我不知道自己做错什么之前一样。

以下是我启动此呼叫方式的示例:

from apiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials

SCOPES = ['https://www.googleapis.com/auth/analytics.readonly']
KEY_FILE_LOCATION = 'client_secrets.json'

def initialize_analytics_reporting():
    """
    Initializes an Analytics Reporting API V4 service object.
    :return: An authorized Analytics Reporting API V4 service object.
    """
    credentials = ServiceAccountCredentials.from_json_keyfile_name(
        KEY_FILE_LOCATION, SCOPES)

    # Build the service object.
    analytics = build('analyticsreporting', 'v4', credentials=credentials)

    return analytics

def get_report(analytics, next_token):
    """
    Queries the Analytics Reporting API V4.
    Args:
      analytics: An authorized Analytics Reporting API V4 service object.
    Returns:
      The Analytics Reporting API V4 response.
    """
    print(analytics.__dict__)
    if next_token == 0:
        return analytics.data.mcf().get(..)
    [...]

不适合我或其他人:

analytics = build('analytics', 'v3', credentials=credentials)

工作!

0 个答案:

没有答案