http://developers.facebook.com/docs/reference/ads-api/batch-requests/にあるバッチ処理の例に従おうとしています。
具体的には、curlコマンド:
curl -F 'access_token=____'
-F 'batch=[
{
"method": "POST",
"relative_url": "6004251715639",
"body": "redownload=1&max_bid=35"
},
{
"method": "POST",
"relative_url": "6004251716039",
"body": "redownload=1&max_bid=35"
},
{
"method": "POST",
"relative_url": "6004251715839",
"body": "redownload=1&max_bid=35"
}
]' https://graph.facebook.com
正常に動作します。
Pythonでurllib2を使おうとすると、「-F」フラグをエミュレートする方法がわかりません。
単一のリクエストに対して「-d」だったとき、私は何をすべきかを知っていました。
curl -d "name=Chm&daily_budget=1000&lifetime_budget=10000
&campaign_status=1" "https://graph.facebook.com/
act_368811234/adcampaigns?access_token=___"
Pythonコードを使用してエミュレートしました:
def sendCommand(self, url, dataForPost=None):
if dataForPost == None:
req = urllib2.Request(url)
else:
req = urllib2.Request(url, dataForPost)
jar = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar))
content = opener.open(req)
response = content.read()
return response
上記の-Fコマンドをエミュレートするにはどうすればよいですか?