Authorize just one spreadsheet in the Google Spreadsheet API - google-sheets

I'm working on some .Net code to collect some data on a server and put it in a Google Spreadsheet. The job needs to run once a day, clear out the sheet and repopulate it. I have all that working, but I can't get the authorization right. I can do it with my personal Google credentials, and I can get it to work with OAUTH by allowing the app to manipulate all my spreadsheets using the https://spreadsheets.google.com/feeds scope. But, what I really want to do is allow my script to read and write just one sheet. Is that possible, and how would I do that?

You are using very old scopes. Look at the drive.file scope
https://developers.google.com/drive/web/scopes

Its not possible using the spreadsheets API. That api is very old and doesnt have a scope for indivdual files.
it might be possible by creating a spreadsheet using the drive API by uploading a CSV with conversion, but you will need permission to create new drive files and that also means permission to the entire drive.

Workaround: Create a new google account and share the spreadsheet with it. Do the OAuth using the new account.
#Zig Mandel is right - the API (Gdata style) wants access to all spreadsheets. But you can workaround the problem using a new account.

Related

Get one stable link for Multiple excel sheets with the same name from Google Drive into PowerBi

On daily basis I am getting an attachment in email. Basically that attachment is an excel spreadsheet. I am pushing that spreadsheet to google drive folder ./attachments using Microsoft Power Automate. The main purpose of pushing that spreadsheet into google drive is to load into PowerBi for Analytics purposes.
In PowerBi I am using the "Web" connector to import the file and it's working fine. The sample link is below.
https://docs.google.com/spreadsheets/u/2/d/1eBJR6wrcFrdjv4Lbf_Wq3MQOeUwBbgLw/export?format=xlsx
The above link exports the file into powerBi and hence I can load data into PowerBi.
The problem is, on daily basis I am getting new file in drive and the Unique Id of the file is not same. In the above example the unique Id 1eBJR6wrcFrdjv4Lbf_Wq3MQOeUwBbgLw will be different for the second file even though I am renaming the file with the same name using Microsoft Power Automate when pushing to Google Drive. eg: "PowerBi load file.xlsx". Is that possible that I can get a stable link for all the files with the same name?.
I have also shared the whole folder ./attachments and tried to get the link of the file but that doesn't work. eg:
https://drive.google.com/drive/folders/1h1VuPtXfWflgIQw7ecMTwweoLblADscq/PowerBi Analytics file.xlsx/export?format=xlsx
Any help, suggestions will be really appreciated.
Thanks everyone.
I believe your goals as follows.
You want to retrieve the file IDs from a filename.
You want to retrieve the file IDs from a shared folder.
Answer for question 1:
In order to retrieve the file IDs from a filename, I think that the method of "Files: list" of Drive API can be used.
The endpoint is as follows.
GET https://www.googleapis.com/drive/v3/files?q=name%3D%27{filename}%27
The search query is name='{filename}'.
In this case, the API key cannot be directly used because the file list tries to be retrieved from the while Google Drive including the file. In this case, the access token is required to be used.
By this, I thought that your goal 2 might be suitable.
Answer for question 2:
In order to retrieve the file IDs from a shared folder, I think that the method of "Files: list" of Drive API can be also used. In this case, at least, the file list is retrieved from the shared folder. By this, the API key can be used.
The endpoint is as follows.
GET https://www.googleapis.com/drive/v3/files?q=%271h1VuPtXfWflgIQw7ecMTwweoLblADscq%27%20in%20parents&key=[YOUR_API_KEY]
The search query is '1h1VuPtXfWflgIQw7ecMTwweoLblADscq' in parents.
In this case, the file list can be retrieved using the API key because the folder is publicly shared and the file list is directly retrieved from the publicly shared.
But, in order to use this, it is required to use the API key. Please be careful this.
Other pattern:
If you want to achieve your goal without the API key and the access token, I would like to propose to use the Web Apps created by Google Apps Script as a wrapper API. When this Web Apps is used, you can achieve above both goals without using the API key and the access token.
The official document of Web Apps is here.
The unofficial document of Web Apps including several sample situations is here.
References:
Files: list
Search for files and folders

Use Google Drive as an external editor

I have a website that stores, parses and display .docx files. I want to give users a way to edit those files.
I don't want to embed a third-party widget in my website and I thought that I could use Google Drive API. My idea is that I can give user a button “Edit in Google Drive” which back to my server somehow.
The problem is that I haven't found neither API function that allows to do that nor examples of such approach.
Am I on the right way? Can my idea work? If yes, then how can I do it?
Look at the drive api. There is one to upload a new file and optionally convert it to native google format.
To upload it, read about using oauth2 to authorize storing it on the user's drive. User must have Drive of course.
After the user finishes editing, they press a button or something on your site so you use the drive api to either read the gdoc and convert yourself to docx or use the drive api to download as docx.
Both uses of drive api are explained in the docs.

Google Private Spreadsheet Javascript Oauth

I have been trying to fully understand the Google APIs so I can grab data from a Google spreadsheet that is private using Javascript.
I am using jQuery and D3.js to create a chart and I want to seamlessly pull the data without the user being redirected to an authorization page. I know I need to use OAuth, but I can't find any examples of how to do this seamlessly through an AJAX call.
https://developers.google.com/google-apps/spreadsheets/#authorizing_requests
This doesn't mention anything that makes it seem like I can do it without an OAuth dialog to the user.
To get a private spreadsheet page, you're going to have to authorize. See Google Spreadsheets API with OAuth 2.0 for Javascript for a complete working OAuth call for a Google Spreadsheet. I used this to create a working database using Google Spreadsheets.
Another way that might work: Fusion Tables. You will have to have a public sheet, but you can make it unlisted meaning it is only available through a link (which you only use in your javascript). It might want a location (as it was designed for spatial data), but you might be able to get around it or just use a dummy value.

Is it possible to change google doc (table) using google API?

Following the API's description :
"The Google Documents List API allows developers to create, retrieve, update, and delete Google Docs"
What if I need to write something in a table using an external application?
This is totally and completely possible. For example, I am using python to create and update Google Doc Spreadsheets based on what the user does. There are multiple languages for you to choose from and all are fairly well documented.

Using Google Spreadsheet as DB for apps

I want to use Google spreadsheets to store data online so multiple people can enter and maintain data, then publish or export (csv, xls, ods) the sheet for their application. What is the easiest way to process the sheet? If the data can be accessed as a link the updates could be immediately reflected in the client's app.
This article Data Scraping Wikipedia with Google Spreadsheets discusses using Google spreadsheets as an application platform.
It already has features that allow you to share the spreadsheet with multiple editors, as well as the ability to define forms that you can invite people to fill out who's results will be entered into the spreadsheet as a row.
Just in case its still vaguely of interest 5 months later, there is a SQL-like wrapper language for Google Spreadsheets at:
http://gqlx.twyst.co.za
Its very much an alpha release - but maybe its of some use or perhaps the code could give you some ideas.
I think if I am clear on your requirements, you want to store your data online in a Google Spreadsheet where multiple people can access that right? Then you want an app to use that data? Correct me if I am wrong.
It is possible to have Google spreadsheet as a database and the client app can directly access that data through APIs - spreadsheet APIs . If you want a simple link where people can go and update - you can also have a web app using google apps scripting. very simple to use and would solve your purpose too , why to export your data to ods, xls, csv, make your app directly over Google Spreadsheet. Would be maintainable too.

Resources