Retrieve access token for Yahoo API using OAuth 2.0 and Python requests -
i trying retrieve access token yahoo api, using explicit grant flow described in document: https://developer.yahoo.com/oauth2/guide/flows_authcode
everything fine until step 4: exchange authorization code access token
i wrote following python script retrieve code:
import urllib2 import requests import json url = 'https://api.login.yahoo.com/oauth2/get_token' body = "grant_type=authorization_code&redirect_uri=oob&code=************" headers = { 'authorization': 'basic **************', 'content-type': 'application/json' } r = requests.post(url, data=body, headers=headers) print r
note: replaced sensitive data "****"
now, when execute script, "401" error message.
i 100% sure login credentials fine, seems related way make request. it's first time using "requests" in python.
would great, if give me feedback on code, , if passing header , body information correctly. unsure passing of body. documentation states following:
sample request body: grant_type=authorization_code&redirect_uri=https%3a%2f%2fwww.example.com&code=abcdef
change body variable dict, i.e.,
body = { 'grant_type': 'authorization_code', 'redirect_uri': 'oob', 'code': '************', }
no other changes needed. hope helps.
Comments
Post a Comment