Android TV
Android TV

Reputation: 11

Need help in Obtaining google OAuth 2.0 access tokens

Trying to Create automate blogger post using Google API's REST calls (not via JavaScript or any other coding languages ). I am able to create all the Google using api Key and Auth2.0 Client. https://console.cloud.google.com/apis/credentials APi and auth2 Since GET calls for Blogger work with API Key, I am able to go all the get activities

In order to POST Blog(Insert: https://developers.google.com/blogger/docs/3.0/using#AddingAPost) using API,need access token for authentication. To get access token for authentication, referred https://developers.google.com/identity/protocols/oauth2/javascript-implicit-flow#oauth-2.0-endpoints. Getting 200 Ok But not getting access token.

enter image description here

POST https://accounts.google.com/o/oauth2/v2/auth

POST data: client_id=.apps.googleusercontent.com&response_type=token&redirect_uri=http://localhost:8080&scope=https://www.googleapis.com/auth/blogger

PostmanResponse with 200Ok

enter image description here

Upvotes: 1

Views: 1036

Answers (1)

Linda Lawton - DaImTo
Linda Lawton - DaImTo

Reputation: 117016

Fist off it wont work with an api key becouse api keys only give you access to public data, private user data needs to be authorized. Using Oauth2 getting you an access token.

To get an access token you need a few things

The first is the link to create the consent screen

https://accounts.google.com/o/oauth2/auth?client_id={clientid}.apps.googleusercontent.com&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=https://www.googleapis.com/auth/analytics.readonly&response_type=code

Then you need to exchange the authorization code

https://accounts.google.com/o/oauth2/token
code=4/X9lG6uWd8-MMJPElWggHZRzyFKtp.QubAT_P-GEwePvB8fYmgkJzntDnaiAI&client_id={ClientId}.apps.googleusercontent.com&client_secret={ClientSecret}&redirect_uri=urn:ietf:wg:oauth:2.0:oob&grant_type=authorization_code

That call will get you an access token.

I'm not exactly sure what it is you are doing but I have a blog post which shows how it all works Google 3 Legged OAuth2 Flow If you just want to know how to set up PostMan to authorize using Google Oauth2 i have a video which shows you how to set it all up How to set up Oauth2 in PostMan. If you actually want to understand how it works i have a video that will walk you though it using CURL Understanding Google OAuth 2.0 with curl

Upvotes: 0

Related Questions