Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting eBay Access Token (Exchanging auth token) with python requests

Tags:

I'm trying to use this guide to get access token.

Here is my main file:

import requests

from utils import make_basic_auth_header, conf
code = '<Auth code here>'
url = "%s/identity/v1/oauth2/token" % conf('EBAY_API_PREFIX')
headers = {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Authorization': make_basic_auth_header()
    }

data = {
    'grant_type': 'authorization_code',
    # 'grant_type': 'refresh_token',
    'state': None,
    'code': code,
    'redirect_uri': conf('EBAY_RUNAME')
}
r = requests.post(
    url,
    data=data,
    headers=headers,
)

Here's the make_basic_auth_header() function:

def make_basic_auth_header():
    auth_header_payload = '%s:%s' % (conf('EBAY_APP_ID'), conf('EBAY_CERT_ID'))
    auth_header_base64 = base64.b64encode(auth_header_payload)
    auth_header = 'Basic %s' % auth_header_base64
    return auth_header

But all I get in r.json() is:

{u'error_description': u'request is missing a required parameter or malformed.', u'error': u'invalid_request'}

I'm frustrated - what am I doing wrong?

like image 915
Dmitry Arkhipenko Avatar asked Jun 20 '17 09:06

Dmitry Arkhipenko


People also ask

How do I get my eBay auth tokens?

To get an Application access token: Navigate to your Application Keys page on the eBay Developer Portal. Next to the App ID listing of the environment you want to generate a token for, click the User Tokens link.

How do I get an access token response?

OAuth: The Videocourse For Dummies If the token access request is invalid or unauthorized, then the authorization server returns an error response. The access token is given by the authorization server when it accepts the client ID, client password and authorization code sent by the client application.

How do you access token in Python?

Obtain Access TokenUse your client ID and client secret to obtain an auth token. You will add the auth token to the header of each API request. The following Python example shows how to obtain an auth token and create the Authorization header using the token.

How long does an eBay user token last?

Tokens are valid for 18 months across multiple sessions of the application. Seven (7) days before a token is due to expire, eBay returns the expiration date in the HardExpirationWarning field in the response of all calls the application makes on behalf of that user.


1 Answers

sorry, I was stupid enough and I didn't see the tickbox on ebay.here's the tickbox, after I've clicked it

like image 168
Dmitry Arkhipenko Avatar answered Sep 23 '22 17:09

Dmitry Arkhipenko