首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Yahoo Gemini API Python获取报表的示例?

Yahoo Gemini API Python获取报表的示例?
EN

Stack Overflow用户
提问于 2016-08-18 13:46:23
回答 1查看 1.6K关注 0票数 1

https://developer.yahoo.com/gemini/

我需要下载雅虎双子座的广告报告。但是雅虎文档只有php代码,没有python。有没有人可以分享一些意见?

我以前做过oauth,但它有一些基本的文档

EN

回答 1

Stack Overflow用户

发布于 2016-08-31 17:53:36

用下面的例子试试这个lib https://github.com/josuebrunel/yahoo-oauth

代码语言:javascript
运行
复制
import urllib
import json
import time
from yahoo_oauth import OAuth2

oauth = OAuth2(None, None, from_file='credentials.json')

if not oauth.token_is_valid():
    oauth.refresh_access_token()

 # get all accounts
response = oauth.session.get("https://api.admanager.yahoo.com/v1/rest/advertiser/")
data = response.content
print data
jdata = json.loads(data)
for j in jdata['response']:
    print "{} {}".format(j['id'], j['advertiserName'])

# get advertiser data
advertiser_id = 12345678
report_date_from = "2016-08-28"
report_date_to = "2016-08-28"
payload = {"cube": "performance_stats",
           "fields": [
               {"field": "Day"},
               {"field": "Impressions"},
               {"field": "Conversions"},
               {"field": "Spend"},
               {"field": "Campaign ID"}
           ],
           "filters": [
               {"field": "Advertiser ID", "operator": "=", "value": advertiser_id},
               {"field": "Day", "operator": "between", "from": report_date_from, "to": report_date_to}
           ]}

response = oauth.session.post("https://api.admanager.yahoo.com/v1/rest/reports/custom?reportFormat=json", json=payload)
print response.content

jdata = json.loads(response.content)
job_id = jdata['response']['jobId']

# you will need to add some loop and waits before the report is ready
time.sleep(60)

url = "https://api.admanager.yahoo.com/v1/rest/reports/custom/{}?advertiserId={}".format(job_id, advertiser_id)
response = oauth.session.get(url)
print response.content

# report will be returned as url
rdata = json.loads(response.content)
if 'status' in rdata['response'] and rdata['response']['status'] == 'completed':
    report = urllib.urlopen(rdata['response']['jobResponse']).read()
    print report
票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39010725

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档