因此,我试图从google analitycs获取一个网站的每个流量源的会话数,但是我遇到了一个错误:
Traceback (most recent call last): File "/home/mrgrj/PycharmProjects/google-api/get_sessions.py", line 3, in from analytics_service_object import initialize_service ImportError: No module named 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客户端库:
^{pr2}$我错过了什么?在
值得一提的是,所有这些工作:
from apiclient.discovery import build
from oauth2client.client import flow_from_clientsecrets
from oauth2client.file import Storage
from oauth2client import tools
目前没有回答
相关问题 更多 >
编程相关推荐