1 of 7

Workflow with �Google Apps Script

or �Online Programming

Friedger Müffke

2 of 7

Use case: Organize Event

  • Create blog entry
  • Send email to attendees
  • Create an event in calendar
  • View a report of replies
  • Update web site

3 of 7

The Basics

  • Menu in spreadsheet
  • Triggers in spreadsheets
  • GUI in sites

4 of 7

Authenticate

/**

 * Authorize against Twitter.  This method must be run prior to 

 * clicking any link in a script email.  If you click a link in an

 * email, you will get a message stating:

 * "Authorization is required to perform that action."

 */

function authorize() {

  

  var oAuthConfig = UrlFetchApp.addOAuthService("blogger");

  oAuthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");

  oAuthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope=http%3A%2F%2Fwww.blogger.com%2Ffeeds%2F");

  oAuthConfig.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken");

  oAuthConfig.setConsumerKey("anonymous");

  oAuthConfig.setConsumerSecret("anonymous");

  var requestData = {

    "method": "GET",

    "oAuthServiceName": "blogger",

    "oAuthUseToken": "always"

  };

  // We make this request to ensure that we are authorized prior to

  // actually using the script.  The following three lines serve no

  // functional purpose otherwise.

  var result = UrlFetchApp.fetch(

      "http://www.blogger.com/feeds/2618574886775036145/posts/default",

      requestData);

  Logger.log("oauth:" + result.getResponseCode() );

  

}

5 of 7

Code Snippets

Add menu:

 var ss = SpreadsheetApp.getActiveSpreadsheet();

    var menuEntries = [ {name: "Send Unsent Rows to Blog", �                           functionName: "putData"}

    ];

    ss.addMenu("Blogger", menuEntries);

Create Blog entry:�

  var response = UrlFetchApp.fetch(url, {method:'post', payload:payload,  contentType:"application/atom+xml", oAuthServiceName: "blogger",

    oAuthUseToken: "always"});

Send email:

  var msg = GmailApp.getMessageById(id);

  var lastMsg = msg.getThread().getMessages()[0];

  lastMsg.replyAll(e.parameter.replyBody);

6 of 7

Urls

http://code.google.com/googleapps/appsscript/

Other online IDEs:

Cloud9 http://c9.io

7 of 7