我正在尝试按照以下示例进行批处理: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 命令?