Yahoo Gemini APIを使ってみた
https://developer.yahoo.com/gemini/:GeminiのAPI叩いて一通り触ったのでメモ
実行方法
- terminalで以下を実行しておく
pip install yahoo_oauth
{
"consumer_key": "<CONSUMER_KEY>",
"consumer_secret": "<CONSUMER_SECRET>"
}
- 実行するコードを用意
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():
# 以下の処理後、ブラウザが開くので、Yahooにログインして、コードを取得してからターミナルに打ち込む
oauth.refresh_access_token()
# Advertiserの一覧を取得
response = oauth.session.get("https://api.admanager.yahoo.com/v1/rest/advertiser/")
data = response.content
print data
jdata = json.loads(data.encode('utf-8'))
for j in jdata['response']:
print "{} {}".format(j['id'], j['advertiserName'])
実行までの流れはDocumentation - Yahoo Developer Network見ると流れがだいたいわかると思います。
Advertiser、Campaignなどの設定値はObjectsのAPI叩くと取得することができます。 https://developer.yahoo.com/gemini/guide/objects.html
実際に配信したデータはhttps://developer.yahoo.com/gemini/guide/reporting/cubes/:Cubesというものを使用するとレポーティングの生成ジョブが動くので、ポーリングして生成ジョブが完了した時点でダウンロードすることが可能となります。