From April 9, 2020, Can I list user’s spreadsheets in the v3 API? - google-sheets-api

Let me ask you about the following statement on this page.
https://gsuiteupdates.googleblog.com/2020/02/sheets-api-migration-update.html
Starting on April 9, 2020, the spreadsheet and spreadsheets.readonly scopes can no longer be used to list a user’s spreadsheets in the v3 API.
I don't use https://www.googleapis.com/auth/spreadsheets scope in my application.
However, I use the following scopes.
https://www.googleapis.com/auth/drive
https://spreadsheets.google.com/feeds
https://docs.google.com/feeds
And I found the following statement on this page.
https://developers.google.com/sheets/api/guides/migration
https://spreadsheets.google.com/feeds
which is an alias
for https://www.googleapis.com/auth/spreadsheets
That page says " the spreadsheet and spreadsheets.readonly scopes", but Is it actually affected if I use another scope?

Related

Read from Google Sheet connection only allows first 100,000 rows

I can only read from the first 100,000 rows of any particular tab in a Google Sheet via the API.
Is this a known limitation of the Google Sheets API? I didn't see a reference to it in the documentation.
Issue and workaround:
I thought that if you want to retrieve the values from Spreadsheet, it seems that when the method of "spreadsheets.get" is used for the Spreadsheet including the large data, the data cannot be correctly retrieved because of an error like Response Code: 413. Message: response too large.. I thought that this might be the reason for your issue. And, in this situation, I confirmed that even when the method is changed from "spreadsheets.get" to "spreadsheets.values.get " and "spreadsheets.values.batchGet", the issue occurred. So I thought that this situation might be the current specification of Sheets API.
But, fortunately, I confirmed that when I tested to retrieve the values from your Spreadsheet using the query language, all values can be retrieved. And also, I confirmed that when I tested to retrieve the values from your Spreadsheet using the Spreadsheet service of Google Apps Script, all values can be retrieved.
So in this answer, I would like to propose these 2 patterns.
Pattern 1:
In this pattern, the values are retrieved by the query language. I thought that in your situation, this might be suitable. The endpoint is as follows.
https://docs.google.com/spreadsheets/d/###spreadsheetId###/gviz/tq?tqx=out:csv&gid=###sheetId###&access_token=###accessToken###
In this case, the access token can be also included in the request header instead of the query parameter. At that time, please use Authorization: Bearer ###. When the above endpoint is accessed using your access token, all values are returned as CSV data.
Pattern 2:
In this pattern, the values are retrieved by the Spreadsheet service of Google Apps Script. The sample script is as follows. When you use this script, please test this script at the script editor of Google Apps Script.
function myFunction() {
const id = "###spreadsheetId###";
const sheet = SpreadsheetApp.openById(id).getSheetByName("Tab 1");
const values = sheet.getDataRange().getValues();
console.log(values.length)
}
When I tested this script for your sample Spreadsheet, 405028 can be seen in the log.
References:
Query Language
Spreadsheet Service

Can you customize / change the spreadsheet ID of a Google Sheet?

Can you customize / change the spreadsheet ID of a Google Sheet (ie. the ID string that shows up in the gsheet's URL)?
I ask this because when looking at the docs for the gsheet api's create() method and looking at the expected request body template, I see that one of the fields available is the spreadsheetId. Does this mean that I can create() a spreadsheet with a specific spreadsheetId?
I find the docs for the API request bodies to be unclear about what certain fields are and when they are optional.
Can you customize / change the spreadsheet ID of a Google Sheet
Answer:
Unfortunately, no this isn't possible.
More Information:
While the spreadsheets.create method does imply that you can select a custom spreadsheet ID when creating a new Spreadsheet, you can see this on the documentation page for the spreadsheet REST Resource (emphasis my own):
Fields:
spreadsheetId string
The ID of the spreadsheet. This field is read-only.
As the spreadsheetId field is read-only, if one provides an ID to the API on creation, then the field will be ignored and an ID will be generated all the same.
References:
Method: spreadsheets.create | Sheets API | Google Developers
REST Resource: spreadsheets | Sheets API | Google Developers

Neto API Limitations

I'm currently attempting to integrate with the Neto Ecommerce API. I've hit all sorts of limitations that I never see on other platforms and the latest is to do with custom fields.
The API Im using is the GetOrders API, and Im following the requirements to fetch transaction information, however custom fields appear to be missing. Hoping someone out there has made use of this API to extract custom fields and can advise on how to go about getting custom field information.
Any tips appreciated
var netoString = '{"Filter":{"OrderID":[""],"OutputSelector":["ID","ShippingOption","DeliveryInstruction","RelatedOrderID","cust1"]};
Is there an undocumented naming convention used to fetch custom fields or other pattern I can try to see if I can fetch the data?
I am not certain this will be the same for the API, but when using exports the correct format to access Custom Sales Order Fields is "customer_ref1".
To get a Custom Customer Fields is "usercustom1"
Note: For the Custom Customer Fields, the numbers do not match up correctly (I.E. usercustom1 doesn't match misc1 in the cpanel). The correct matches are:
misc1=usercustom1
misc2=usercustom4
misc3=usercustom5
misc4=usercustom6
misc5=usercustom7
misc6=usercustom11
misc7=usercustom12
misc8=usercustom13
misc9=usercustom14
misc10=usercustom15
misc11=usercustom16
misc12=usercustom17
misc13=usercustom18
misc14=usercustom19
misc15=usercustom20
misc16=usercustom21
misc17=usercustom22
misc18=usercustom23
misc19=usercustom24
misc20=usercustom25
misc21=usercustom10
misc22=usercustom26
misc23=usercustom27
misc24=usercustom28
misc25=usercustom29
misc26=usercustom30
misc27=usercustom31
misc28=usercustom32
misc29=usercustom33
misc30=usercustom34
misc31=usercustom35
misc32=usercustom36
misc33=usercustom37
misc34=usercustom38
misc35=usercustom39
misc36=usercustom40

Google Visualization API Query fails with new Google Spreadsheets

I work for a Google Apps Reseller and I implement gadgets for our clients.
We have several gadgets that use Google Visualization API to query a spreadsheet (with a dynamic id) and display the result in a table.
We are using this piece of code:
function drawVisualization() {
var oldSpreadsheetUrl = "https://docs.google.com/spreadsheet/tq?key=<ss_id>";
var newSpreadsheetUrl = "https://docs.google.com/spreadsheets/d/<ss_id>/gviz/tq";
var query = new google.visualization.Query(oldSpreadsheetUrl);
query.setQuery("SELECT A,B");
query.send(handleQueryResponse);
}
function handleQueryResponse(response) {
if(response.isError()) {
console.log(response.getMessage());
} else {
console.log("NUMBER OF COLUMNS: " + response.getDataTable().getNumberOfColumns());
}
}
And testing with this sample spreadsheet (New Google Spreadsheet)
SPREADSHEET ID: 1qMvY3y4MkwoK1UvCA9A8dW4BbmhH1iMwWqGLEM5vjJk
As long as we query an old spreadsheet everything works ok, but if we query a new spreadsheet (with the standard url - oldSpreadsheetUrl) the request fails with a timeout exception and we get a 404 exception.
This is the message we get in the Browser Console:
http://i.imgur.com/h4DjyQ6.png
We were able to make the query work anyway, by using this new url in the datasource:
"https://docs.google.com/spreadsheets/d/<spreadsheet_id>/gviz/tq"
But with this notation the setQuery directive is ignored and all of the three columns are returned instead of the first two ("SELECT A,B").
We are using this in several gadgets and therefore want to know:
How can we overcome the setQuery bug?
Is there a programmatic way to know if a spreadsheet is a new version or an old version?
Thank you in advance.
Regards,
Riccardo
I ran into this same problem a few weeks ago when we did some testing with the new Google Sheets. Basically, the old Google Sheets expect a URL with the following format:
https://spreadsheets.google.com/tq?key={key}
While the new Google Sheets expects a URL with this format:
https://docs.google.com/spreadsheets/d/{key}/gviz/tq
You should be able to use the domain to distinguish between old and new Google Sheets. Failing that, you could always look for /gviz/ to tell if the new Google Sheets are being used. You can find additional information in this bug report.
In regards to your other point about setQuery, I've just noticed this morning while debugging my own issue that column IDs are being returned by the Visualization API as "Col 0", "Col 1" etc. instead of "A", "B" etc. So that's likely why your ("SELECT A,B") query isn't working. I've also just logged a bug for this issue.
Hope that helps.

Google custom search REST number of results (num field)

I'm trying to figure out how to force google custom search to give me back 20 results per page.
I've tried to send this REST request configuring my new Custom Search Engine to:
Standard edition: Free, ads are required on results pages.
https://www.googleapis.com/customsearch/v1?key=AIzaSyCgGuZie_Xo-hOECNXOTKp5Yk7deryqro8&cx=015864032944730029962:5ipe0q27hgy&q=test&alt=json&num=20
IT NOT WORKS!
but
https://www.googleapis.com/customsearch/v1?key=AIzaSyCgGuZie_Xo-hOECNXOTKp5Yk7deryqro8&cx=015864032944730029962:5ipe0q27hgy&q=test&alt=json&num=10
IT WORKS!
But reading documentation at
https://developers.google.com/custom-search/docs/xml_results#numsp
it says that:
Optional. The num parameter identifies the number of search results to return.
The default num value is 10, and the maximum value is 20. If you request more than 20 results, only 20 results will be returned.
Note: If the total number of search results is less than the requested number of results, all available search results will be returned.
Someone has experienced this problem?
PS: I've tried also to send that REST request configuring my new Custom Search Engine to:
Site Search: Starts at $100 per year, ads are optional on results pages.
But nothing has changed no way to obtain 20 results in a request/page
This documentation url has descriptions of each parameter. It also says num is restricted to integers between 1 and 10, inclusive.
https://developers.google.com/custom-search/v1/using_rest#query-params