Integration Google Cloud Storage and Google App Script

3,005 views
Skip to first unread message

Sebastian Segura Camacho

unread,
Nov 15, 2011, 11:24:32 PM11/15/11
to gs-dis...@googlegroups.com
Hello. 

I have a script on Google Apps Script that use spreadsheet and fusion table to work (The script make request to build a form, send and read data), it seams that the script is making more request than they can suppor, is possible to use Google Cloud Storage to make that my script works with a better performance? How easy will be the integration?

Thank you for your help

Google Storage Team

unread,
Nov 17, 2011, 1:08:49 AM11/17/11
to gs-dis...@googlegroups.com
Hi Sebastian,

When you say your script is making more requests than they can support, I assume you are running into some sort of storage space constraint in Google Apps (hence your post to this group). Let me know if I misunderstood.

There is currently no direct integration between Google Apps Script and Google Cloud Storage but we're always interested in hearing about customer needs. If you can share some information about what you are trying to do and how you would like to see such an integrated service work, that would be helpful to know.

Thanks for your input,

Marc
Google Cloud Storage Team

--
You received this message because you are subscribed to the Google Groups "Google Cloud Storage" group.
To view this discussion on the web visit https://groups.google.com/d/msg/gs-discussion/-/odMsfdHHUUAJ.
To post to this group, send email to gs-dis...@googlegroups.com.
To unsubscribe from this group, send email to gs-discussio...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gs-discussion?hl=en.

Franz Noel Tanglao

unread,
Mar 16, 2012, 8:44:59 PM3/16/12
to gs-dis...@googlegroups.com
Hello Marc, 

To be honest with you I was assuming that Google Cloud Storage is a Google Database of some sort where you can save records and create tables. I am not sure if Sebastian felt the same way. But, finally, I got to try Google Cloud Storage and it looks great. However, I cannot add tables, I cannot add fields, nor data. Finally, I got to say to myself, Oh... Now I know the purpose.

Google Cloud Storage is for storing files and is not a database. I could have asked the same question as what Sebastian asked. Thanks, Sebastian for asking this question, don't worry you're not the only one. LOL!

Google Cloud Storage Team

unread,
Aug 27, 2012, 1:25:39 PM8/27/12
to gs-dis...@googlegroups.com
Hi Pavan,

I'm assuming you want to write your data to Google Cloud Storage, not Google Drive. Some people have gotten confused between the two products in the past, so I just wanted to double check.

Assuming you really want to store your data in Google Cloud Storage, the next question would be whether this needs to be automated. If not, then you could export/download your csv data into a local file and then use gsutil to store the results in Google Cloud Storage. If this process needs to be automated (which, I suspect is the case), I don't know whether it's possible to write data directly into Google Cloud Storage from Google Apps Script but I'll look into that today and try to get you a more definitive answer.

Marc
Google Cloud Storage Team

On Mon, Aug 27, 2012 at 8:32 AM, pavan <pavankum...@gmail.com> wrote:
Hello,

Problem: 
We're using Google Spread Sheets for our purpose using Google App Script, We've a requirement that we would like to write the data from Google Spread Sheet to a csv file and store the csv file in Google Cloud Storage.

Can you please let me know how can I solve the above problem using Google Apps Script? If not possible, please let me know the way how to solve this problem? 

It's a urgent task for us, please respond asap. Thanks in advance

Thanks,
Pavan 

--
 

Murali Krishna

unread,
Aug 27, 2012, 1:36:04 PM8/27/12
to gs-dis...@googlegroups.com

The AppEngineFile class can help. You can use that to create files in GCS. However, I have had to use REST API for deleting those files when needed.

Thanks,
Murali

--
 
 

Google Cloud Storage Team

unread,
Aug 27, 2012, 3:53:33 PM8/27/12
to gs-dis...@googlegroups.com
Pavan,

A co-worker pointed me to the UrlFetchApp class:
Looks like it now has built-in (experimental) oauth support and a code sample so I gave it a try. Unfortunately, the code sample illustrates using twitter, not a Google API, but I found this discussion thread, which provides some details about using this with a Google API. I managed to get this working and was able to read a cloud storage object from Apps Script (code is shown below). See if you can modify this to do an upload and let me know if you get stuck (privately via gs-...@googlel.com, if you don't mind).

Thanks,

Marc

function myFunction() {
  // Setup OAuthServiceConfig
  var oAuthConfig = UrlFetchApp.addOAuthService("google");
  oAuthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");
  oAuthConfig.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken");
  oAuthConfig.setConsumerKey("REDACTED");
  oAuthConfig.setConsumerSecret("REDACTED");

  // Setup optional parameters to point request at OAuthConfigService.  The "twitter"
  // value matches the argument to "addOAuthService" above.
  var options =
    {
      "oAuthServiceName" : "google",
      "oAuthUseToken" : "always"
    };

  var result = UrlFetchApp.fetch("http://storage.googleapis.com/bucket/object", options);
  Browser.msgBox(result.getContentText());
}
--
Marc Cohen
Google Cloud Storage Team

Google Cloud Storage Team

unread,
Aug 28, 2012, 11:45:35 PM8/28/12
to gs-dis...@googlegroups.com
Hi Pravan,

To do an upload rather than a download, insert the following three key/value pairs into the options object in the code I shared earlier:

    "method" : "put",
    "payload" : "foo",
    "contentType": "text/plain",

Of course, you'll want to customize the payload value (which is used to populate the body of the PUT request) and you may need to tweak the contentType value depending on the type of data you're sending. You can read more about the UrlFetchApp object here.

Marc

On Tue, Aug 28, 2012 at 6:48 PM, pavan <pavankum...@gmail.com> wrote:
Hi Marc,

Thanks for your quick turn around. The example in the update provided by you, fetching the data from Google Cloud Storage. But, I need it in other way. I need a way to store in Google Cloud Storage using Google App Script.

Please provide the sample code, if it's possible OR let me provide the other ways to solve this issue.

Thanks,
Pavan

--
 
 

pavan

unread,
Sep 3, 2012, 11:21:49 AM9/3/12
to gs-dis...@googlegroups.com, gs-...@google.com
Hi Marc,

It's an urgent task for  me. Can you please reply asap, once you've the time. 

Thanks,
Pavan

Google Cloud Storage Team

unread,
Sep 3, 2012, 10:58:18 PM9/3/12
to gs-dis...@googlegroups.com
Hi Pavan,

See responses below (inline). We're getting into some areas which are more about Apps Script than Cloud Storage, so if you have any followup questions, feel free to send them privately to gs-...@google.com.

Thanks,
Marc

On Sat, Sep 1, 2012 at 10:43 AM, pavan pavankumar.nitw12-at-gmail.com <trax-proxy-disa...@google.com> wrote:
Hi Marc,

Thanks for your reply. Am little confused now. I tried using URLFetch object, but I'm not sure how to process the response object to get the desired action. 


Marc> The response is returned in an HTTPResponse object, which is described here.
 
Here's my understandings and questions as of now:
* I studied the doc of Google Cloud Storage (https://developers.google.com/storage/docs/reference-methods) and found the following: 
There is XML API and JSON API which performing different type of operations on Google Cloud Storage.


Marc> When you use raw HTTP, as with the Apps Script UrlFetchApp object, you're using the XML API.
 
* From the sample code provided in the previous mail by you, by using PUT we can upload a file.
  Where do I need to pass file information to upload??

Marc> In my sample code, the uploaded contents is conveyed in the value associated with the "payload" key in the objects variable ("foo" in my sample).
 
* For retrieving (using GET method) where it storing the downloaded file.


Marc> The returned data is available in the HTTPResponse object. It's up to you to retrieve the data and store it wherever you like.
 
Lets take the following example and explain me clearly how to proceed here. 
  Eg:-  
    * lets say bucket_name: XXX_YYY
    * I've one Google Spread Sheet named abc, 
    * I need to upload the file abc to bucket (XXX_YYY)
    * How can I do this? 

   Similarly,
    * Once the above completed I'll have file abc in bucket (XXX_YYY)
    * How can I download and have it in my google Docs

Can you please send me the complete code for the above tasks?(preferably by email : pavankum...@gmail.com)

I think you'll get a lot more out of this experience by writing this app yourself. Hopefully the previous sample code and the responses above are of some help.
 
Am eagerly waiting for your reply?

Thanks,
Pavan 


pavan

unread,
Sep 10, 2012, 1:22:32 PM9/10/12
to gs-dis...@googlegroups.com, gs-...@google.com
Hi Marc,

Thanks for your reply. 

Am able to get the data from Google Cloud Storage. But many of the times, I found that script failing with "Unexpected Error:".

Can you please let me know the reason for the same(what is the error here)? How to fix this issue?

Thanks,
Pavan

Google Cloud Storage Team

unread,
Sep 11, 2012, 5:32:02 PM9/11/12
to gs-dis...@googlegroups.com
Pavan,

It's difficult to say without more details (e.g. App Script code, screenshot or copy/paste of entire error message, any special conditions which trigger this error, etc.). If you'd care to share more supporting details privately (gs-team AT google.com, not gs-discussion), I'd be happy to take a look.

Thanks,
Marc

--
 
 
Reply all
Reply to author
Forward
0 new messages