Stephen Flanagan
Stephen Flanagan

Reputation: 311

Unable to authorise with Pinterest API Oauth

I am trying to follow the Pinterest API instructions here: https://developers.pinterest.com/docs/api/authentication/.

I can complete the first step, obtaining an access code, with this URL: https://api.pinterest.com/oauth/?response_type=code&redirect_uri=https://localhost/&client_id=XXXXXXXXXXXXX&client_secret=YYYYYYYYYYYYYYYYY&scope=read_public,write_public&state=myystatestring

That gives me the code: https://localhost/?code=ZZZZZZZZZZZZ&state=mystatestring

However, when I try and complete the second step from the docs, 'Exchanging authorization code for an access token' (using a post request), I can't authorise. Using this command:

curl --data "grant_type=authorization_code&client_id=XXXXXXXXXXXXXXX&code=ZZZZZZZZZZZ" https://api.pinterest.com/v1/oauth/token

I get:

{"status": "failure", "code": 3, "host": "coreapp-devplatform-devapi-171", "generated_at": "Wed, 30 Sep 2015 16:21:26 +0000", "message": "Authorization failed.", "data": null}

I've tried using the requests library within Python also, but same result. I've also noticed that in the first step you can change 'code' to 'token' and get a result that includes 'access_token=', but I can't either exchange that or use it for access directly.

Any guidance much appreciated!

Upvotes: 2

Views: 2603

Answers (2)

user3206684
user3206684

Reputation: 1

I know a lot of time passed however the second URL has to be something like https://api.pinterest.com/v1/oauth/token?grant_type=authorization_code&client_id=XXXXXXXXXXX&client_secret=XXXXXXXXXXXXX&code=XXXXXXXXXXXX

in Original post the app secret is missing

Upvotes: 0

Stephen Flanagan
Stephen Flanagan

Reputation: 311

And actually I now see this has been asked and answered yesterday, at this question: Auth Exception in Pinterest API

"The docs are wrong. You have to include your client_secret in this step (step 2), not step 1. So add "&client_secret=" to postStr. – Zack Argyle"

Once I changed to this it worked perfectly:

curl --data "grant_type=authorization_code&client_id=XXXXXXXXXXXXXXX&code=ZZZZZZZZZZZ&client_secret=YYYYYYYYYYYYYYYYY" https://api.pinterest.com/v1/oauth/token

Response:

{"access_token": "token_string_here", "token_type": "bearer", "scope": ["read_public", "write_public", "read_private", "write_private", "read_write_all"]}

Thanks Zack!

Upvotes: 3

Related Questions