pinterest / pinterest-python-sdk

An SDK that makes it quick and easy to build applications with Pinterest API.
Apache License 2.0
43 stars 28 forks source link

BUG - Exchange the code for an access token #110

Closed ALEXDINO7 closed 1 year ago

ALEXDINO7 commented 1 year ago

i created a new code and use this example as discribed in docs and i get a 401 error

https://www.pinterest.com/oauth/? client_id={YOUR_CLIENT_ID}& redirect_uri={YOUR_REDIRECT_URI}& response_type=code& scope=boards:read,pins:read& state={YOUR_OPTIONAL_STRING}

dfana01 commented 1 year ago

Hi @ALEXDINO7, can you share the following information?

ALEXDINO7 commented 1 year ago

Hi @ALEXDINO7, can you share the following information?

  • SDK full code
  • Logs

This is my code to Exchange the code for an access token

i use the docs here

https://developers.pinterest.com/docs/getting-started/authentication/#3.%20Exchange%20the%20code%20for%20an%20access%20token

url_api = "https://api.pinterest.com/v5/oauth/token"

headers = { 'Authorization': '{HERE I ADDED MY CORRET CLIENT_ID:CLIENT_SECRET}', 'Content-Type': 'application/x-www-form-urlencoded' } params = { 'grant_type':'authorization_code', 'code': 'HERE I ADDED MY CODE ITS WORKING ', 'redirect_uri':'https://www.HEREMYWEBSITE.com/'

      }

response = requests.post(url_api, headers=headers, data=params)

print(response.status_code)

HERE I GET 401 CODE

dfana01 commented 1 year ago

Hi @ALEXDINO7 are you adding a Basic and encoding the client_id:client_secret with base 64 prefix to the headers?

url_api = "https://api.pinterest.com/v5/oauth/token"
headers = {
    'Authorization': 'Basic {HERE I ADDED MY CORRET CLIENT_ID:CLIENT_SECRET}',
    'Content-Type': 'application/x-www-form-urlencoded'
}

params = {
    'grant_type': 'authorization_code',
    'code': 'HERE I ADDED MY CODE ITS WORKING ',
    'redirect_uri': 'https://www.heremywebsite.com/'
}

response = requests.post(url_api, headers=headers, data=params)

print(response.status_code)
ALEXDINO7 commented 1 year ago

yes i use this website https://www.base64encode.org/

i generated Authorization by doing this client_id:client_secret

did you mean i include the word basic + client_id:client_secret ??

dfana01 commented 1 year ago

Yes, did you?

ALEXDINO7 commented 1 year ago

Yes, did you?

yes the same error

dfana01 commented 1 year ago

@ALEXDINO7 looks like you have some authentication error not related to the SDK, please ask for support for your developer app

You can request it here: https://help.pinterest.com/en/contact?page=overview_page_2 using the option Pinterest API and Developer Tools > API Access.