Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from urllib import urlencode
- import pycurl
- import pprint
- import json
- from io import BytesIO
- data = BytesIO()
- c = pycurl.Curl()
- c.setopt(c.URL, 'https://partners.com/api/v2/login')
- post_data = {'username': 'user', 'password': 'pass'}
- postfields = urlencode(post_data)
- c.setopt(c.POSTFIELDS, postfields)
- c.setopt(c.WRITEFUNCTION, data.write)
- c.perform()
- dictionary = json.loads(data.getvalue())
- pprint.pprint(dictionary["access_token"]) #Con Comillas
- print(dictionary["access_token"]) #Sin Comillas
- c.setopt(c.URL, 'https://partners.com/api/v2/traffic-channels')
- post_data = {"trafficChannel":{"name":"martin","status":0,"billedEvent":"ai","env":"desktop","dealType":"fixed_price","cost":2,"floor":3,"optimizeAllAdSources":"true","optimizeFor":"fillRate","publisher":"5a01fee6cf4b4c000288e254"}}
- postfields = urlencode(post_data)
- c.setopt(c.POSTFIELDS, postfields)
- c.perform()
- curl 'https://partners.com/api/v2/login' -d 'username=johnSmith&password=mYpassw0rd'
- Response:
- {
- "access_token":"SKbWW6YEtCdkxOO6g7teO3JMKQNSTQa9I2V00T6kGSX7BWVrMPbJsCaKNJ2SuAoyHxqdr8CqpA1v193mbbwi86MCCKpx4sr55ziF",
- "token_type":"bearer",
- "user_id":"aCdsvU98ks5jFIxiKDGsW7G"
- }
- }
- curl 'https://partners.com/api/v2/traffic-channels'
- -H 'Authorization: Bearer SKbWW6YEtCdkxOO6g7teO3JMKQNSTQa9I2V00T6kGSX7BWVrMPbJsCaKNJ2SuAoyHxqdr8CqpA1v193mbbwi86MCCKpx4sr55ziF'
- -d '{"trafficChannel":{"name":"tc2","status":0,"billedEvent":"ai","env":"desktop","dealType":"fixed_price","optimizeAllAdSources":false,"optimizeFor":"ecpm","useCache":false,"publisher":"1fi6cfjz3l23cmr67t4u39m"}}'
- Response:
- {
- "trafficChannel":{
- "id":"3kuop6vuo1qf46kszixf2me",
- "name":"tc2",
- "createdOn":"2017-04-04T09:57:58.463832363Z",
- "lastModified":"2017-04-04T09:57:58.463828293Z",
- "createdBy":"fAq04U17V6YCYkHBGniyAh8",
- "modifiedBy":"fAq04U17V6YCYkHBGniyAh8",
- "org":"b04q1yxgsk6udnrfng7qf05",
- "dealType":"fixed_price",
- "billedEvent":"ai",
- "publisher":"1fi6cfjz3l23cmr67t4u39m",
- "optimizeFor":"ecpm",
- "dealTypeExceptions":null,
- "env":"desktop",
- "waterfalls":0
- }
- }
Add Comment
Please, Sign In to add comment