1
https://developer.yahoo.com/gemini/Yahoo Gemini API Python獲取報告的示例?
我需要下載雅虎雙子座廣告報告。但雅虎文檔只有php代碼和沒有python。有人可以分享任何投入嗎?
我以前做過的OAuth,但它有一些基本的文檔
https://developer.yahoo.com/gemini/Yahoo Gemini API Python獲取報告的示例?
我需要下載雅虎雙子座廣告報告。但雅虎文檔只有php代碼和沒有python。有人可以分享任何投入嗎?
我以前做過的OAuth,但它有一些基本的文檔
試試這個LIB https://github.com/josuebrunel/yahoo-oauth下面
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
我非常感謝你分享這段代碼。它幫助我極大地入門。這個信息是超級利基!再次感謝! – Jarad
例子你讓它工作進行到底? – Kubber