Google API get reviews for my business using java script - javascript

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.

Related

Google Calendar API and API Key issues

OK.
So I am building a simple app for a friend. The biggest requirement for this app is that he wants a user to be able to go to his site and create an event on his google calendar. I have let him know that this calendar will have to be made public and he is fine with that. I created an API Key with google and the first call against the API with the API Key to get calendar events for a given day works fine. The second request, a post, returns :
err(401)"API keys are not supported by this API. Expected OAuth2 access token or other authentication credentials that assert a principal."
It doesn't make sense that his website would be an OAuth app because that would require the user have a gmail account.
There has got to be some kind of way to make this work ...
Thanks Everyone
I just want to make a post request to Google Calendar API using an API Key.
API keys only give read access. If you want write access you need the permission of the owner of the calendar
options
Create a google workspace account and use a service account with domain wide deligation
use Oauth2 have your friend auth it once store the refresh token and use the refresh token to request a new access token when ever you want to write to the calendar
neither option will work with client side JavaScript switch to a server side programming language

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

Accessing Google Analytics Data With API Key Only

I'm trying to use Google Analytics API in Javascript. I want to:
Query Data for a specific website (under my control)
Use the data to build an open-to-the-public dashboard
Every example I can find requires you to use OAuth to authenticate before you can query data. Because I only want to query (not delete/modify), is there a way to use a simple API Key to grab the data I need?
Yes and No. The Google Analytics Core Reporting API is an Authenticated API and requires the use of OAuth2, authorized with the appropriate scope:
https://www.googleapis.com/auth/analytics.readonly
The API key simply identifies your Google Project, it does not necessarily grant you authorization to read the data of your Google Analytics Accounts, even if that account is associated with the same Google Login. The API key is usually public and lives on the client browsers, it would not be secure to grant access to anyone's Google Analytics Account data simply if they had access to a particular key.
What you are going to need to do is use a service account to access the data. Take a look at the Google Analytics Demos and Tools site. There they have a really good example example of using a service account server side to generate an access token and then has the JavaScript Client library make the final request. Alternatively you could build something akin to the Google Analytics Super Proxy which can query the API on your behalf and generates a public URL which can then be queried separately.

unable to obtain access_token Google+ signin using auth2 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.

Categories

Resources