Google Sheet API v4 - google-sheets

I try to use example "Read multiple ranges":
https://sheets.googleapis.com/v4/spreadsheets/{SpreadsheetID}/values:batchGet?ranges=Sheet1!B:B&ranges=Sheet1!D:D&valueRenderOption=UNFORMATTED_VALUES?majorDimension=COLUMNS
from: Google Sheets API v4 example
I replaced "spreadsheetId" with my spreadsheet id.
But when I send GET request (by Postman) I receive:
{
"error": {
"code": 403,
"message": "The request is missing a valid API key.",
"status": "PERMISSION_DENIED"
}
}
Than I used https://developers.google.com/oauthplayground/
I made authorisation for Spreadsheet API v4 with my email and at the end I generated a long link with key and saw correct response with content of my data table.
My question is next:
Why it's imposible to use the example from Google API (https://developers.google.com/sheets/api/samples/reading) only replace the spreadsheet id.
P.s Link to my spreadsheet is public, My spreadsheet is public and available in JSON format and what is correct use of url for Google Spreadsheet API v4 in order to send batchGet with multiple requests?
P.s.s I use another approach and it works but why first approach (v4) doesn't work:
https://spreadsheets.google.com/feeds/list/{SpreadsheetID}/od6/public/values?alt=json
When I tried to combine 2 APIs in one request and received and error "Inconsistent repeating query parameter ranges":
https://spreadsheets.google.com/feeds/list/{SpreadsheetID}/od6/public/values:batchGet?ranges=Sheet1!B:B&ranges=Sheet1!D:D&valueRenderOption=UNFORMATTED_VALUES?majorDimension=COLUMNS
======================================
Edited:
SpreadSheetID: 1KBk1J7TJCwnayMnTbaysqvFk98kVDdxXWNw2JYc3bW0
Available in incognito mode: Spreadsheet
In JSON format: JSON
Reference: Google Sheets API v4: Read multiple ranges
The same example with SpreadSheetID: ERROR 403

I believe you are missing API in the url. This is from google spreadsheet api doc.
To acquire an API key:
Open the Credentials page in the API Console.
API keys: A request that does not provide an OAuth 2.0 token must send
an API key. The key identifies your project and provides API access,
quota, and reports.
The API supports several types of restrictions on API keys. If the API
key that you need doesn't already exist, then create an API key in the
Console by clicking Create credentials > API key. You can restrict the
key before using it in production by clicking Restrict key and
selecting one of the Restrictions. To keep your API keys secure,
follow the best practices for securely using API keys.
After you have an API key, your application can append the query
parameter key=yourAPIKey to all request URLs.
The API key is safe for embedding in URLs; it doesn't need any
encoding.
Google Spreadsheet Docs

You have to make sure to pass in the key=YOUR_API_KEY as the request parameter.
For example:
https://sheets.googleapis.com/v4/spreadsheets/{sheet_id}/values/Sheet1!A1:D5?key={YOUR_API_KEY}

In addition to #skamble89's answer, this 403 error is usually caused by incorrect or missed some configuration in Authorizing Requests. If you're authorizing requests with OAuth 2.0, make sure you use the proper scope with it.
Make sure you have a permission to call this spreadsheet and you enable the Sheets API in your developer console.

The Sheet must have a Public link for the API KEY to be used.
You have to share the spreadsheet, select "Get Link", and "Anyone with the Link".
That gives a link like this: https://docs.google.com/spreadsheets/d/1ShTP408LPzLOGjqXQTRcmXXXXXXXXXXXXXPUteQmY7o/edit?usp=sharing.
So there, the Sheet ID is after: /d/, is: 1ShTP408LPzLOGjqXQTRcmXXXXXXXXXXXXXPUteQmY7o.
curl "https://sheets.googleapis.com/v4/spreadsheets/1ShTP408LPzLOGjqXQTRcmXXXXXXXXXXXXXPUteQmY7o/values/A1%3AD3?key={YourApy"

Related

PHP Google Adwords API get campaigns

I am using the google adwords API to connect with adwords and list all the campaingns. I am connecting with OAuth to the Adwords account and become an access_token and an refresh_token, which I am saving into the DB.
Now I am trying to make this example:
https://github.com/googleads/googleads-php-lib/blob/master/examples/AdWords/v201802/BasicOperations/GetCampaigns.php
But my access_token and my refresh_token are in the database and all the API OAuth2 credentials are in one configuration array.
How to query hte google adwords service with this credentials?
The OAuth2TokenBuilder class referred to in line 81 of your example and copied below has several methods that'll let you set parameters instead of reading them from the config file.
$oAuth2Credential = (new OAuth2TokenBuilder())->fromFile()->build();
The fromFile method will read parameters from the config file. Your new code might look something like this:
$oAuth2Credential = (new OAuth2TokenBuilder())
->withClientId(your oauth2 client id here)
->withClientSecret(your oauth2 client secret here)
->withRefreshToken(your stored refresh token here)
->build();
High level overview of some other issues with the Google AdWords API here:
https://pete-bowen.com/how-to-use-the-google-adwords-api-to-automate-adwords

What does YouTube mean when they say "key" in their documentation?

In the YouTube reference documentation found here:
https://developers.google.com/youtube/v3/docs/
It says:
"Every request must either specify an API key (with the key parameter)"
However, the language that is used in the Google Developer Console, they call credentials "Client ID" and "Client Secret"
Which one do they mean? Or are they talking about something completely different when they say "key?"
The key that the document is referring to is the API key. As stated in the link that you have provided:
Every request must either specify an API key (with the key parameter) or provide an OAuth 2.0 token.
If you will be accessing user's private data or simply insert, update, and delete request OAuth 2.0 (clientID and client secret) must be use.
One example would be Videos: insert.
If you just list videos using search keyword, request for a method that do not need to identify a particular user, you can use an application API key.
https://www.googleapis.com/youtube/v3/videos?key={API-key}&fields=items(snippet(title,description,tags))&part=snippet&id={video_id}
Hope this helps.

Could not fetch Places - REQUEST_DENIED

I want to fetch places from google place api, I just download SPGooglePlacesAutocomplete & created new API Key enable place, direction & map api's from Google API Console still i am getting error alert.
Any help very much appreciated.
I assume you are using key which is made for iOS apps.But SPGooglePlacesAutocomplete might be using Google's public API to fetch the places list. So in that case you should use key for your browser apps. You can refer following link for more elaborated ans
REQUEST_DENIED when using the Google Places API
The Google Places API Web Service enforces a default limit of 1,000 free requests per 24 hour period.
The "status": "REQUEST_DENIED" is returned by the Google Places API Web Service when:
You have not activated the Google Places API Web Service in the Google API Console.
The key parameter is missing from your request. EX.
https://maps.googleapis.com/maps/api/place/add/json?key=YOUR_API_KEY
The key parameter does not match the your API key in the Google API Console.
Your API key has not been correctly set up in the Google API Console:
If you are using a browser-restricted API key, check that your
allowed referer(s) are correct.
If you are using a server-restricted API key, check that your allowed
IP(s) are correct.
API keys with Android or iOS restrictions are not supported. Please
use a generic (unrestricted) API key, or a key with browser or server
restrictions.
The request was not sent as an HTTPS request, HTTPS is required for all Google Places API Web Service requests.
The incorrect HTTP method was used to send the request:
All requests must be sent as a GET request except for Place Add.
All Place Add requests must be sent as a POST request.
You have to Create API Key from this link & from google console make sure you have enabled Google Place API.

Youtube data api return dailyLimitExceededUnreg reach

We are using the YouTube Data API to get the YouTube channel information, it was working before two days now it is giving me below error:
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "dailyLimitExceededUnreg",
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
"extendedHelp": "https://code.google.com/apis/console"
}
],
"code": 403,
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
}
}
Is there any new update on YouTube Data API?
Can anyone help me to resolve this issue?
In order to access any Google API you need to identify your application. This rule has not been enforced on all Google APIs. If you say your request has worked in the past I suspect that they have begun to enforce this now with the YouTube API.
The problem is that you have either not authenticate your application using Oauth2 or you are not sending an API key along with this request.
You need a Google Account to access the Google Developers Console, request an API key, and register your application.
Create a project in the Google Developers Console and obtain authorization credentials so your application can submit API requests.
After creating your project, make sure the YouTube Data API is one of the services that your application is registered to use:
a. Go to the Developers Console and select the project that you just registered.
b. Open the API Library in the Google Developers Console. If prompted, select a project or create a new one. In the list of APIs, make sure the status is ON for the YouTube Data API v3.
If your application will use any API methods that require user authorization, read the authentication guide to learn how to implement OAuth 2.0 authorization.
see Getting started
I was getting the same error. The mistake I was making is not setting the API Key value while requesting. Please set the API Key attribute.
If you are using youtube data v3 api use following code snippet.
playlistItemsListByPlaylistIdRequest.setKey(YOUR_API_KEY_VALUE);
If you are using the Html request, then use following format :
https://www.googleapis.com/youtube/v3/playlistItems?part=snippet%2CcontentDetails&maxResults=8&playlistId={PLAYLIST_ID}&key={YOUR_API_KEY}

Invalid Developer Key

I was reaching the youtube api quota limit while building my application so I added a developer key to the request and now I get a 403 error: Invalid Developer Key.
I've tried recreating my project and api key multiple times without any luck. I've tried adding the key to the URI as well as sending it in a header:
$c1 = curl_init($feedURL);
curl_setopt($c1, CURLOPT_HTTPHEADER, array(
'X-GData-Key: key=AIzaS...',
'GData-Version: 2'
));
My application is simple, all requested data is public, so I don't see a reason to use the Zend PHP Client.
You're using a v3 "API key" while querying v2 of the API.
v3 "API key"s are obtained from the Access tab of https://code.google.com/apis/console/ and are what you use to make non-authenticated requests to any of the APIs listed on that console.
v2 "developer key"s are obtained from http://code.google.com/apis/youtube/dashboard/ and is what you're looking for.
I believe that one of the goals is to retrofit v2 of the API to start supporting "API key"s from the API console, but that isn't something that's possible at this time.

Resources