我正在尝试用python发出请求。我的代码在CURL中,但我对此一无所知,我需要使用URL发出请求。 我的意思是例如这可能是我需要的网址:
https://www.googleapis.com/doubleclickbidmanager/v1/sdf/download/ADVERTISER_ID/filterIds/2368848
CURL代码:
curl --request POST \
'https://www.googleapis.com/doubleclickbidmanager/v1/sdf/download' \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{"filterIds":[2368848],"filterType":"ADVERTISER_ID"}' \
--compressed
Python代码:
import httplib2
import json
import csv
from oauth2client.client import OAuth2WebServerFlow
client_id = r''
client_secret = r''
redirect_uri = ''
scope = ['https://www.googleapis.com/auth/doubleclickbidmanager']
flow = OAuth2WebServerFlow(client_id=client_id,
client_secret=client_secret,
scope=scope,
redirect_uri=redirect_uri)
auth_uri = flow.step1_get_authorize_url()
code = raw_input()
credentials = flow.step2_exchange(code)
http = httplib2.Http()
http = credentials.authorize(http)
post = http.request('url', 'POST')