unable to obtain access_token Google+ signin using auth2 javascript - javascript

I am trying to integrate google+ login with my website using javascript sdk, Though I am able to validate the user I need to obtain an access token on successful signin which I pass to the server to obtain further information. I went through the documentation in google developer console in this link: Google Sign-In for Websites
in that is could see a method GoogleUser.getAuthResponse() whose response object must contain an access_token.
However in my response object I couldn't find the access_token , but all the remaining key were present. I am not sure if the documentation is outdated.
Please help with me a solution this problem.

Related

Google API get reviews for my business using java script

I am trying to get google reviews for my business but struggling with implementing it. Can someone share how to get the latest/top 5 reviews using google business API using JavaScript/Postman? I was trying to do so:
GET:
https://accounts.google.com/o/oauth2/auth?client_id=MY_CLIENT_ID.apps.googleusercontent.com&client_secret=MY_CLIENT_SECRET&scope=https://www.googleapis.com/auth/business.manage&response_type=token&redirect_uri=https://developers.google.com/oauthplayground
but it doesn't work.
Was trying also testing it on Google oauth playground
filling:OAuth flow: Client-side
Use your own OAuth credentials: my Client ID here
Step 1:
Authorize API: https://www.googleapis.com/auth/plus.business.manage
but here I am getting:
Error 400: redirect_uri_mismatch
The redirect URI in the request, https://developers.google.com/oauthplayground, does not match the ones authorized for the OAuth client. To update the authorized redirect URIs, visit: https://console.developers.google.com/apis/credentials/oauthclient/938304287177-nkvm5mqk3f5uq9lt9j2srqlgd0bjihip.apps.googleusercontent.com?project=938304287177
The redirect uri in your project on Google cloud console must exactly match the redirect uri you are sending from The easiest solution is to go to your project and add it.
https://developers.google.com/oauthplayground
Which is not the same as as you have an extra slash on the end
https://developers.google.com/oauthplayground/
This video will walk you though it. Google OAuth2: How the fix redirect_uri_mismatch error.
Question from Comments
how can I get the reviews using just API key without a need to authorize it using gmail account?
If you check the documentation Method: accounts.locations.reviews.list you will find that it says the following
API keys only allow you to access public data, the data you are trying to access is private user data and therefore requires authorization in order to access it. You can not use an API key to access this data you must be authorized using one of the above scopes. A video which explains api keys. Everything you need to know about Google API Key's, and where to get one.

I need a way to get updated oauth tokens for google photos

I'm currently working on an application for myself in which I need access to my own photos/albums on Google Photos. I have gotten by using the oauth 2.0 token generated in the playground, but I'd like to get a more permanent solution that does not require me manually regenerating the token. Is this possible with Google Cloud? The app is meant to run in daemon, so this makes any option with consent pages unusable. The scopes I'm using are:
https://www.googleapis.com/auth/photoslibrary.sharing
https://www.googleapis.com/auth/photoslibrary.readonly.appcreateddata
https://www.googleapis.com/auth/photoslibrary.readonly
I have tried using the https://accounts.google.com/o/oauth2/token and https://accounts.google.com/o/oauth2/auth endpoints to generate one programatically, but the only minor success I had was /auth sending me to a consent screen. I've also looked at using the refresh token given by Google Oauth playground with no luck there either.
Just looking to see if there is anything that I am missing.. This is my first post on stackoverflow, so please let me know if you need any more information.
I was unable to make it an internal app as it was for personal use and not for an organization.
Solved this by first using the google api package to create my own access/refresh token for my oauth client, then calling the https://oauth2.googleapis.com/token endpoint each time to generate a valid access token. I hope this can be helpful to someone else!
According to the setup documentation, as long as your app is marked as internal, you should not need to verify the app and can use it without the consent screen.

acquire of google api key for OAuth 2.0 In Javascript

After getting an access-token, I don't know how to use google API.
I tried to add 'access_token' but the error message displays 403: the request cannot be identified with a client project. Please pass a valid API Key with the request.
so I mixed up because I didn't get any API Key from OAuth. Please, does anyone knows how to get valid API key?
Have you looked at Using OAuth 2.0 for Client-side Web Applications?
The process is described quite nicely there. If you successfully received and verified the access_token, you can scroll down to Calling a Google API to see how to make API calls using the access_token.
If you need help with using a specific Google API, visit that API's documentation page. (e.g. Maps API, Drive API etc.)
Make sure you have needed APIs enabled and relevant credentials set up correctly from the Google API Console
You have to provide the api key along with the url; to do that just add the parameter "key=API_KEY", for example:
sheets.googleapis.com/v4/spreadsheets{{spreadsheet ID}}/values/{{the name of the spreadsheet}}!A1:D3?key={{API_KEY}}

Remove Google Drive Web Auth token javascript

I have set up Web Authentication for Google Drive API. I used the tutorial here, and I can successfully upload and download files. I cannot, though, find reference in the API about how to revoke the Authentication (I want to give my users the option).
I found this on SO : gapi.auth.signOut() but it does not remove auth, nor does it give an error in the console. Is there not a gapi.auth method to remove the token?
To revoke token, you can make a REST call to :
https://accounts.google.com/o/oauth2/revoke
and includes the token as a parameter:
curl https://accounts.google.com/o/oauth2/revoke?token={token}
Google reference

Logging in to my website with Google (what to do after getting access_token)

I want to allow my users to have an account on my website using their Google Account to log in (pretty much like on Stack Exchange here). There's a lack of post-2012 guides on this matter on the net so I'm following Google's guides which I find a bit cryptic.
I've successfully followed this guide on Initiating the Google+ Sign-In flow with JavaScript and I can get the access_token with authResult['access_token'].
What should I do after this? This access_token is apparently unique and will be different each time the user logs in. Now that my user has logged in using Google+ how can I POST a code to my server page to uniquely identify this user and start a PHP session for his account?
Make a POST request to your server with the access_token so your server can make an authenticated request to people.get. This will return the users Google+ id an optionally their email address you can use to identify them.

Categories

Resources