Accessing Google Drive Files On The Server Side Of A Website - javascript

So I'm making a website. I need to submit a form to a server to be processed. This is required to process login information. This server-side script needs to access a plain-text file which is stored on my Google Drive in order to confirm that the user input is valid. The only way that I know how to access a file on Google Drive is through Google Apps Script.
Is there a way to handle forms on the server-side that are submitted from another website with HTML or JavaScript in Google Apps Script? or Is there a way to use PHP with Google Apps Script? or Is there another more efficient way that I can access and write to files on my Google Drive directly from my website?

You can make an HTTP request to an Apps Script and get a response back. Take a look at the Content Service. Google also has a PHP Client API that you can use. You would need to use the Drive Service.

Related

How do I allow users to edit my Sheets file via my own Google Scripts Web App?

I'm quite new Google Scripts. I'm trying to create a web app through which users can log in (with their Gmail accounts) and modify a Google Sheet. Here's a screenshot of the registration page.
Initially, the user logs in via their existing Google account and this page is displayed. Upon clicking the button, what I want is for the script to add their submitted information and their current email to a Google Sheet. Once their info is in the Sheet, they only need to log in via Google to gain access to the system. However, when I try this with another account I get this error:
Is this a permissions problem? Or does Google Scripts not allow this kind of direct manipulation of files on my Drive? Here are my permissions settings for my web app:
Is this at all possible?
From your question, I could understand that the settings of your Web Apps is as follows.
Execute the app as: User accessing the web app
Who has access to the app: Anyone
For above Web Apps, you want to make users access to the Web Apps using each browser.
Confirmation points:
From above situation, please confirm the following points. At first, I think that when the Spreadsheet you want to put the values is in each user's Google Drive, no error occurs. So from your question, I thought that the Spreadsheet might be in your Google Drive.
Although I'm not sure about your whole script, if the Google Spreadsheet which is used in your script of Web Apps is in your Google Drive, it is required to shared the Google Spreadsheet with the user. Even when the script of Web Apps is the container-bound script of the Spreadsheet and getActiveSpreadsheet() is used, it is required to share the Spreadsheet with the user.
When you want to put the values to your Spreadsheet in your Google Drive when the user submitted the form, please share the Spreadsheet with the user as the writer.
When you want to only read the values from your Spreadsheet in your Google Drive when the user submitted the form, please share the Spreadsheet with the user as the viewer.
Also, you can publicly share. But I thought that this might not be the direction you expect.
Other method:
If you don't want to share the Spreadsheet with the user, how about the following workaround?
Deploy new Web Apps as following settings.
Execute the app as: Me
Who has access to the app: Anyone, even anonymous
In this case, you can also make user access to this Web Apps using a key as the query parameter.
When Who has access to the app: Anyone is used, it is required to share the script of new Web Apps with the user. So I proposed to use Anyone, even anonymous for this situation.
When the form is submitted, the values are put to your Google Spreadsheet using this new Web Apps.
In this case, new Web Apps is used as the wrapper API for putting the values to Spreadsheet.
References:
Web Apps
Taking advantage of Web Apps with Google Apps Script

Uploading to Google Cloud via an asp.net webpage

I have a webpage through which my users, using a mobile phone, can take pictures and upload them (hopefully) to the Google Cloud (I've got a JSON file, a platform project and an associated storage bucket, as well as all the login details).
However, I'm pretty new to all this and need to know how I'd get the file (coming from a standard <input file="" name="fileupload"/> ) to the Google Cloud space, and also to retrieve the URI of the file. Given that it's an asp.net webpage, I have access to Javascript and C#.
Thanks!
I have a couple of suggestions for you. We have other customers that have solutions which are similar to this architecture and so your proposed solution is good.
Google Cloud Storage (GCS) has a feature called Signed URLs. This allows you to generate a secure URL to an object in a GCS bucket. My colleague wrote the C# sample for this:
https://cloud.google.com/storage/docs/access-control#signing-code-csharp
There's a method in here that you can reuse GetSigningURL.
Each time a user requests the web page, you should generate a Signed URL and use this as the destination URL for the file upload location in your HTML.
If your HTML is generated by ASP.NET (MVC, Web Forms, Web Page), then you can make the call to GetSigningURL when the page is generated server-side. If not, you should wrap the C# code in a Web API and then you could use, e.g. jQuery ($.ajax), to call it from your client.
You may run your ASP.NET code on Google Cloud Platform using either Windows on Google Compute Engine or using Custom Runtimes on Google App Engine.
Full disclosure: I'm a Googler working in cloud as a Strategic Customer Engineer.

Is it possible to retrieve the contents of a Google Sites page via Javascript?

I have been looking for Javascript code to access the Google Sites API, but I can't find anything definite.
All I want to do is be able to take the contents of a page I made on Google Sites and display them on another website I own.
Is this possible, and if so, are there tutorials or example code available?
You can retrieve contents of Google Sites via API:
https://developers.google.com/google-apps/sites/docs/1.0/developers_guide_protocol#ContentFeedGET
You could create a PHP/Python script on your own server to execute the API commands on demand and return the result. Via JavaScript/AJAX you could access it local on your server, without cross origin problems.

Embed Google Analytics in Laravel

I set up a website with laravel 4.
The website has no front facing site ...
The website sends a file as response to a link earlier generated.
So there is no html / blade template.
How can I embed Google Analytics within Laravel without using html output?
Is there a chance to call the Google Analytics JavaScript with php?
Thanks
The Google Analytics Measurement Protocol is what you're looking for:
https://developers.google.com/analytics/devguides/collection/protocol/
It allows you to send hits directly to Google Analytics via simple HTTP requests, which you should easily be able to do from your PHP back-end.

Upload file to my google drive from anyone using javascript

I am new to google api. I am able to do this file upload from app script and any file which is uploaded through that script get stored to my drive only.
But how to do this using javascript.
Example on google : https://developers.google.com/drive/web/quickstart/quickstart-js
shows how to do this but file gets uploaded to the same user's drive who is authorizing the app. How to restrict it to my drive only.
Thanks
Simple answer is you cant with JavaScript. The reason being is that JavaScript works with OAuth2 this requires that you ask the user permission to access your data.
If you want to have it access your drive account you would have to save the refreshtoken some place and then send that when ever the script was loaded. JavaScript is client sided so anyone that checked the code on the page would then have all the information they needed to do what ever they wanted with your drive account. Security wise that's a bad idea.
I recommend you look into using a server sided scripting language like PHP. You might want to consider a service account. Note: everything will be owned by the service account so you will either have to give the Service account access to your Google Drive files or you will need to move your drive files to the Service account.
If you don't want the service account to have the files you could go with normal Oauth2 save the refresh token and then store it in the server sided code there wont be as much of security risk there.

Categories

Resources