python open api,友盟爱恨情仇之Open API接口文档(python版)

他曾是一匹来自北方的狼

为何近日却愁成了加班狗

平日里他曾是安静的导表小哥

每天从友盟导出数据,风雨无阻

这一天,他眉头紧锁

发现了……某个任务需要导出72个excel表

一向懒惰的他开始寻找破阵之术

友盟,无数数据产品经理、数据分析师的数据分析利器,以统计称霸江湖多时。

江湖流传着一份《友盟 Open API.pdf》文档,本文基于Python语言,将文档中大部分数据接口的调用,写成Python函数,以期望方便使用。

数据获取流程大概如下:

通过账号密码获取token ---- 通过token获取appkey ----通过token和appkey获取其他数据

auth_token认证

接收参数:

参数名

是否必须

参数说明

类型及范围

email

必选

用户名

string

password

必选

密码

string

接口调用成功返回数据示例:

{"code":200,"success":"ok","auth_token":"bgymNcCjPC3gY9TUE241"}

#该函数返回一个auth_token

def authorize(user, pasw):

url = 'http://api.umeng.com/authorize'

body = {'email': "%s"%(user), 'password': '%s'%(pasw)}

response = requests.post(url, params = body)

return response.json()['auth_token']

获取APP列表

接收参数:

参数名

是否必须

参数说明

类型及范围

per_page

可选

每页数量,默认为20

int

page

可选

第几页,默认为1,从1计数

int

q

可选

要查询的app名

string

接口调用成功返回数据示例:

[

{

"name": "Android Demo App",

"category": "阅读资讯",

"created_at": "2011-04-28T11:04:02Z",

"updated_at": "2013-03-06T09:31:10Z",

"platform": "android",

"appkey": "4db949a2112cf75caa00002a"

},

{

"name": "iPhone Demo App",

"category": "工具",

"created_at": "2012-02-23T15:15:33Z",

"updated_at": "2013-03-06T09:31:11Z",

"platform": "iphone",

"appkey": "4f46581552701523110000c9"

}

]

#获取APP列表

def apps(auth_token):

url = 'http://api.umeng.com/apps?&auth_token=%s'%(auth_token)

response = requests.get(url)

return response.json()

获取APP数量 ——所登录友盟账号下的APP数量

#获取APP数量 ——所登录友盟账号下的APP数量

def apps_count(auth_token):

url = 'http://api.umeng.com/apps/count?auth_token=%s'%(auth_token)

response = requests.get(url)

return response.json()['count']

获取APP的基本数据 ——应用列表-全部应用

#获取APP的基本数据 ——应用列表-全部应用

def base(auth_token):

url = 'http://api.umeng.com/apps/base_data?auth_token=%s'%(auth_token)

response = requests.get(url)

return response.json()

获取渠道列表

参数名

是否必须

参数说明

类型及范围

appkey

必选

APP标识

string

date

可选

查询日期,格式为2013-03-01,也可以是today或yesterday,默认为today

string

per_page

可选

单页显示数量,默认为10

string

page

可选

当前页数,默认为1

string

响应字段

字段说明

date

查询日期(默认值是today)

total_install_rate

当前渠道新增用户占当日新增用户的比例

active_user

活跃用户

install

新增用户

total_install

总用户数

channel

渠道名称

id

渠道的id

#获取渠道列表

def channels(appkey,auth_token):

url = 'http://api.umeng.com/channels?appkey=%s&auth_token=%s'%(appkey,auth_token)

response = requests.get(url)

return response.json()

获取当前所有版本和基本数据

参数名

是否必须

参数说明

类型及范围

appkey

必选

APP标识

string

date

可选

查询日期,格式为2013-03-01,也可以是today或yesterday,默认为today

string

响应字段

字段说明

date

查询日期(默认值是today)

total_install_rate

当前渠道新增用户占当日新增用户的比例

active_user

活跃用户

install

新增用户

total_install

总用户数

version

版本号

#获取当前所有版本和基本数据

'''

def versions(appkey,auth_token):

url = 'http://api.umeng.com/versions?appkey=%s&auth_token=%s'%(appkey,auth_token)

response = requests.get(url);print(response.status_code)

return response

获取今日的基本数据

参数名

是否必须

参数说明

类型及范围

appkey

必选

APP标识

string

响应字段

字段说明

date

日期

active_user

活跃用户

installations

总用户数

launches

启动次数

new_users

新增用户

#获取今日的基本数据

def today_data(appkey, auth_token):

url = 'http://api.umeng.com/today_data?appkey=%s&auth_token=%s'%(appkey,auth_token)

response = requests.get(url);print(response.status_code)

return response

获取任意日期的基本数据

参数名

是否必须

参数说明

类型及范围

appkey

必选

APP标识

string

date

可选

查询日期,格式为2013-03-01

string

响应字段

字段说明

date

日期

active_user

活跃用户

installations

总用户数

launches

启动次数

new_users

新增用户

#获取任意日期的基本数据

def base_data(appkey, date, auth_token):

url = 'http://api.umeng.com/base_data?appkey=%s&date=%s&auth_token=%s'%(appkey,date,auth_token)

response = requests.get(url)

return response.json()

获取用户群列表

#获取用户群列表

def segmentations(appkey, auth_token):

url = 'http://api.umeng.com/segmentations?appkey=%s&auth_token=%s'%(appkey,auth_token)

response = requests.get(url)

return response.json()

获取新增用户汇总

参数名

是否必须

参数说明

类型及范围

appkey

必选

APP标识

string

start_date

必选

开始日期,2012-08-15

string

end_date

必选

结束日期,2012-09-04

string

period_type

可选

日期类型,daily / weekly / monthly,默认为daily

string

channels

可选

渠道id,以,分割,如4f6c5c4852701534c9000007,4f86490752701575f5000004

string

versions

可选

版本号,以,分割,如1.1.0,1.1.3

string

segments

可选

分群id,以,分割,如4f6c5c4852701534c9000008,4f86490752701575f5000005

string

#获取新增用户汇总

def new_users(appkey, start_date, end_date, auth_token):

url = 'http://api.umeng.com/new_users?appkey=%s&start_date=%s&end_date=%s&auth_token=%s'%(appkey, start_date, end_date, auth_token)

response = requests.get(url)

return response.json()

获取活跃用户汇总

参数名

是否必须

参数说明

类型及范围

appkey

必选

APP标识

string

start_date

必选

开始日期,2012-08-15

string

end_date

必选

结束日期,2012-09-04

string

period_type

可选

日期类型,daily / weekly / monthly,默认为daily

string

channels

可选

渠道id,以,分割,如4f6c5c4852701534c9000007,4f86490752701575f5000004

string

versions

可选

版本号,以,分割,如1.1.0,1.1.3

string

segments

可选

分群id,以,分割,如4f6c5c4852701534c9000008,4f86490752701575f5000005

string

#获取活跃用户汇总

def active_users(appkey, start_date, end_date, auth_token):

url = 'http://api.umeng.com/active_users?appkey=%s&start_date=%s&end_date=%s&auth_token=%s'%(appkey, start_date, end_date, auth_token)

response = requests.get(url)

return response.json()

获取自定义事件Group列表

参数名

是否必须

参数说明

类型及范围

appkey

必选

APP标识

string

start_date

必选

开始日期,2013-01-23

string

end_date

必选

结束日期,2013-02-03

string

period_type

必选

日期类型,daily / weekly / monthly,默认为daily

string

versions

可选

版本号以,分割,如1.1.0,1.1.3

string

#获取自定义事件Group列表

def group_list(appkey, page, per_page, start_date, end_date, period_type, auth_token):

url = 'http://api.umeng.com/events/group_list?appkey=%s&page=%s&per_page=%s&start_date=%s&end_date=%s&period_type=%s&auth_token=%s'%(appkey,page,per_page,start_date,end_date,period_type,auth_token)

response = requests.get(url)

return response.json()

获取自定义事件列表

参数名

是否必须

参数说明

类型及范围

appkey

必选

APP标识

string

start_date

必选

开始日期,2013-01-23

string

end_date

必选

结束日期,2013-02-03

string

period_type

必选

daily / weekly / monthly,默认为daily

string

group_id

必选

从group_list列表中取到的group_id

string

#获取自定义事件列表

def events_list(appkey, start_date, end_date, period_type, group_id, auth_token):

url = 'http://api.umeng.com/events/group_list?appkey=%s&start_date=%s&end_date=%s&period_type=%s&group_id=%s&auth_token=%s'%(appkey, start_date, end_date, period_type, group_id, auth_token)

response = requests.get(url)

return response.json()

获取事件消息数/独立用户数

参数名

是否必须

参数说明

类型及范围

appkey

必选

APP标识

string

start_date

必选

开始日期,2013-01-23

string

end_date

必选

结束日期,2013-02-03

string

period_type

必选

daily / weekly / monthly,默认为daily

string

group_id

必选

从group_list列表中取到的group_id

string

type

必选

count / device,默认为count

string

#获取事件消息数/独立用户数

def events(appkey,group_id,type,start_date,end_date,auth_token):

url = 'http://api.umeng.com/events/daily_data?appkey=%s&group_id=%s&type=%s&start_date=%s&end_date=%s&auth_token=%s'%(appkey,group_id,type,start_date,end_date,auth_token)

response = requests.get(url)

return response.json()

获取参数列表 / 获取参数消息数

当自定义事件有配置参数的时候,获取自定义事件的点击数据,如下:

#获取参数列表

def parameter_list(appkey,event_id,type,start_date,end_date,auth_token):

url = 'http://api.umeng.com/events/parameter_list?appkey=%s&event_id=%s&type=%s&start_date=%s&end_date=%s&auth_token=%s'%(appkey,event_id,type,start_date,end_date,auth_token)

response = requests.get(url)

return response.json()

#获取参数消息数

def parameter_data(appkey,event_id,start_date,end_date,auth_token):

url = 'http://api.umeng.com/events/parameter_data?appkey=%s&event_id=%s&label=navigate&start_date=%s&end_date=%s&auth_token=%s'%(appkey,event_id,start_date,end_date,auth_token)

response = requests.get(url)

return response.json()

哎呀,肚子好饿,吃饭去了,实际应用参考下文~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值