我试图按照发现批量处理的例子: http://developers.facebook.com/docs/reference/ads-api/batch-requests/如何效仿卷曲-F在蟒蛇的Facebook图形API批量要求
具体而言,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上面的命令?
谢谢!这工作! 只需添加dataForPost = urllib.urlencode(dataForPost)即可使其正常工作。 – eran