Reputation: 137
I am lost, I have no idea what should I do to get the access token. This is the code that I have tried, please help, please!
This is for Oauth2.0 token, and the API is Ocotoparse.
from octoparse import Octoparse as oct
import requests
host='https://advancedapi.octoparse.com/token'
url=host+'username={onlyfiii}&password={19970909huy}&grant_type=password'
r=requests.post(url)
username='onlyfiii'
password='19970909huy'
{
"access_token": "ABCD1234",
"token_type": "bearer",
"expires_in": 86399,
"refresh_token": "refresh_token"
}
Upvotes: 0
Views: 284
Reputation: 1247
I hope that's not your real password, if it is, change it immediately.
You need to send the request parameter as a form encoded POST request body, not as url parameters.
import requests
import json
url = 'https://advancedapi.octoparse.com/token'
payload = {
'username': 'onlyfiii',
'password': '19970909huy',
'grant_type': 'password',
}
r = requests.post(url, data=payload)
json_response = json.loads(r.text)
access_token = json_response['access_token']
See the API docs:
Request Content Type
application/x-www-form-urlencoded
Upvotes: 1