错误python:使用google analitycs API时没有名为分析服务对象的模块

时间:2015-04-15 09:07:21

标签: python google-analytics google-analytics-api

所以,我正在尝试从网站的google analitycs获取每个流量来源的会话数,但我遇到了这个错误:

  

Traceback(最近一次调用最后一次):文件   " /home/mrgrj/PycharmProjects/google-api/get_sessions.py",第3行,在          来自analytics_service_object import initialize_service ImportError:没有名为analytics_service_object的模块

到目前为止我的代码看起来像这样:

from analytics_service_object import initialize_service

def get_source_group(service, profile_id, start_date, end_date):
    ids = "ga:" + profile_id
    metrics = "ga:sessions"
    dimensions = "ga:channelGrouping"
    data = service.data().ga().get(
        ids=ids, start_date=start_date, end_date=end_date, metrics=metrics,
        dimensions=dimensions).execute()
    return dict(
        data["rows"] + [["total", data["totalsForAllResults"][metrics]]])


if __name__ == '__main__':
    service = initialize_service()
    profile_id = "your_profile_id"
    start_date = "2014-09-01"
    end_date = "2014-09-30"
    data = get_source_group(service, profile_id, start_date, end_date)
    for key, value in data.iteritems():
        print key, value

我还安装了 Google API Python客户端库

pip install -U google-api-python-client
pip install python-gflags

我错过了什么?

提及所有这些工作:

from apiclient.discovery import build
from oauth2client.client import flow_from_clientsecrets
from oauth2client.file import Storage
from oauth2client import tools

0 个答案:

没有答案