How can I use Google Sheets API as database? - javascript

I am trying to write a web application in javascript that reads and writes to a single Google sheet as a database. It basically reads from the sheet, make sure everything is in order, then writes to the sheet. All users will be using the same sheet, however I don't want the sheet to be able to be accessed outside the web application except for trusted users. I have a problem with writing to the sheet, as apparently it has to do O_Auth2 which has such poor documentation(where the hell do I put the key in the PUT request????) and all users would have to sign into my account. I don't think this would really work. Any ideas????
Thanks so much.

Related

Using google spreadsheet as a database for a tumblr theme?

I am currently using tumblr as a website for my club. On tumblr there is a page, where every club member has a 'profile card' with their name, description and profile image.
I wondered if there is any way to create a google spreadsheet with the members' information and use the spreadsheet as a database, which can be accessed in the tumblr theme's HTML code.
I have been reading about Google App Scripts and JavaScript, but I just can't seem to connect those with tumblr and my idea (and actually I am not sure if tumblr is supporting it either).
So basically what I want to do in the tumblr HTML code is:
-Access a google spreadsheet
-Parse the data into a two-dimensional array
-Use array values to create new div elements
The reason, why I want to do this is because I don't want the members to login in tumblr and go through the hassle to mess with the code. They should be able to easily put their information into a spreadsheet, which is connected to the tumblr website, and every time the spreadsheet is changed, the website just needs to be refreshed and it is again up to date.
I will be thankful for any kind of help =)
I have done a similar task using Google Sheets as a database for small sets of data to be edited by non technical maintainers, and it can work quite well.
You have mentioned that you can add custom Javascript, so it should be possible in your case. Here are the general steps you would take:
Setup your sheet to be accessed via API
Pull data via the Javascript fetch API
Process and display the data on your tumblr site
This actually works quite well and allows for easy updating of what is essentially static data.
For more info on how you can open up your sheet and access it with the API check out this article or ones like it available via Google.

Google Sheets API Randomly Denying Access

Hello Stackoverflow users,
I am trying to pull data from a Google Sheet that I own, but without requiring the user to login to my google account. I am using the code available here provided by Google. I have inserted the appropriate Client ID, Sheet ID, and API Key. I am pulling data from two different sheets, and for several weeks, this had been working well and the data had been pulling successfully.
About 3 days ago, however, without any code changes, the sheet is now denying access randomly. At certain times, it still works, and other times, it throws an error that reads "The caller does not have permission." As far as I can tell, there isn't any pattern for when it works and doesn't work.
I have read many articles about this error and a few other questions already asked about this error and tried everything I could find. I have ensured that the sheet is published to the web, ensured that none of the authentication keys or other ID's have changed, and that it is shared to anyone on the web with view access. Has anyone else been experiencing this issue and if so, how should one go about fixing this?
Side Note: I'm relatively new to working with the Google Sheets API, so if more information is needed, I'm more than willing to provide it.
Thank you.

Is there a way to display data from a private google spreadsheet as a chart on a website?

I am doing a project for my school. I have logged in the number of visitors who come to the school using a car, a bike, a bicycle or some other form of transport on a google spreadsheet. I want to be able to display all the data in the form of charts on my school website in order to keep track of the CO2 emissions caused by people to come to school daily.
I read about the google spreadsheet api but can't understand how to get data from the spreadsheet without making it public.
Any help would be greatly appreciated.
Thanks.
no need to code this in apps script. Google sheets natively supports publishing charts.
https://support.google.com/docs/answer/78052
Depending on how you published the chart, its a different process to update the chart as the data changes.
If you used "publish to the web", simply republish, or modify the URL to remove the range (with some caveats, see this help topic on ways to do it. Its an old post and the new sheets publish url may be different or allow open ranges (like A1:C). https://productforums.google.com/forum/?hl=en#!category-topic/docs/how-do-i/ZRpghByKHNM
If you publish the chart inside a doc or presentation, see http://googleappsupdates.blogspot.pe/2016/05/embed-charts-from-google-sheets-in.html which is a more streamlined way to update the chart, but requires an intermediate doc/slide.
Yes definitely, write code in Google app script to get required data from spreadsheet, deploy your script (anyone even anonymous option), change version of script each time when you are changing code and deploy again.
Get URL of deployed app script, do ajax call to that url from your javascript code (in your web application) and get required data and use it to show chart using any chart plugin from jquery.

Using Google Drive as a database for a login form

Recently i created a website with Godaddy's website builder . In the website there is a free membership, though here is the problem.
Godaddy's website builder doesn't allow you to create a login area, you have to do that with your own tools, and the other problem is website builder does not allow you to upload any files like html or php or install anything like MySql. It does allow you though to put some code in your website. The current way I'm managing the login function is by putting some JavaScript in my website which i found elsewhere , the bad thing is the usernames and passwords are shown in the source code and every time there is a new user i have to change the code. Not only that, the link of the membership area is also in the source code, currently i change it every month. After doing lots of research and finding nothing i had an idea.
By putting a text file on google drive which contains all usernames and passwords, i could make it act as a database. Then put some code in my website which reads the text file in google drive. If this didn't work (Which i think it does) How about using a spreadsheet? And the code on my website reads the spreadsheet. The link to the membership area (Which is also in my website) Could be in another text file.
I'm new with code, and that is really all i need, the code to make this idea work. If anyone can write the code, please post it below. You have no idea how much this will help. Thanks in advance - Braulio
If you can use javascript, you could probably use something like
https://www.firebase.com/
or any other 'database as a service' type thing. This will allow you to query the database, and save to the database with client side javascript.
With firebase you could do something roughly like
var myFirebaseRef = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com/");
myFirebaseRef.set({
username: "Braulio",
password: "pass"
}
});
Just one option
yes you can use a google spreadsheet. yes it will be 100% secure. look at the spreadsheet api for this.
however, beware of the limitations:
there is a limit as to how many cells you can have (in the millions).
since all the requests will be made from the same google account, rate limit quotas will apply, and total daily api calls will be limited (to a few million i think).
if you really will have many users, you can workaround these limitations by caching as much as possible the spreadsheet data in your backend.

How to prevent script sharing from it's users?

I am making a small payment system, basically it's just a point system, you pay say 1 USD and you get 100 points which is used later on in a game project to get bonuses. It's a script for game servers, something like a user panel.
Now, the script system is ready, but I'm afraid to give it away, since than someone will share it and it will spread all over the gaming area. What would be the solution keeping it working only if I give them a permission?
I thought about re-making whole code and make it work on my website but I don't think that people will want to put their SQL data to website that located NOT on their host. Please help me out, at least with some clues, maybe its possible to make some widgets? or maybe some license system?
I'm really lost.
You should implement the logic on the server side as an api REST call and include in the script only an ajax call to the api. You can limit the use of the api through an api key that you'll provide only to qualified sites.
You'd need to implement some sort or serverside authentication/api so that only varified users can use the script. Much like how software checks a licence.
On script load your javascript could make a ajax call to a server passing through the users IP, auth key, username etc etc.
This can then be varified on the server, maybe returning a dynamically generated url containing a javascript file which contains your business logic
(so that urls are dynamically generated for that users session only)
That way people cant hot link the script, and the script you give out is solely the ajax call
(With the business logic script injected on auth)

Categories