Google Apps Script lets you automate and extend Google Apps. Using Apps Script, businesses can build efficient solutions to meet their requirements such as:
Google Apps Script lets you automate and extend Google Apps. Using Apps Script, businesses can build efficient solutions to meet their requirements such as:
Join us on August 18th, 2011 for the Google Apps Script Hackathon. If your organization uses Google Apps and you want to explore how you can use Google Apps Script to create custom functions or automate repetitive tasks, then this hackathon is a perfect opportunity to learn. Google engineers will be available to answer your questions and help you learn Apps Script throughout the day’s agenda. We’ll provide food, refreshments, and experts to help you learn to use Apps Script and write your own scripts. Just bring your laptop, ideas, and enthusiasm to complete the mix. We hope to see you there!

What: Apps Script Hackathon
Date: Thursday, August 18th, 2011
Time: 2pm to 7pm EDT
Where: 76 9th Avenue, New York, NY
Register: Space is limited, register here.

For those who cannot attend in person, we invite you to try out a number of self-paced tutorials on the Apps Script documentation site.



Saurabh Gupta profile | twitter | blog

Saurabh is a Developer Programs Engineer at Google. He works closely with Google Apps Script developers to help them extend Google Apps. Over the last 10 years, he has worked in the financial services industry in different roles. His current mission is to bring automation and collaboration to Google Apps users.


What can you do with a little bit of Apps Script?

At Google, we all use email very heavily-- for communicating with other Googlers, for task management, and to mail around funny pictures of kittens. Because of the volume of email we all deal with (the internet is full of kittens), a lot of Googlers subscribe to the “inbox zero” philosophy. In ...

What can you do with a little bit of Apps Script?

At Google, we all use email very heavily-- for communicating with other Googlers, for task management, and to mail around funny pictures of kittens. Because of the volume of email we all deal with (the internet is full of kittens), a lot of Googlers subscribe to the “inbox zero” philosophy. In inbox zero you try to keep your inbox empty of all but the emails you currently need to deal with.

What is Gmail Snooze?

In managing our inboxes, one feature that we really wanted was for Gmail to let you “snooze” an email. To snooze an email means to archive it for now, but to have it automatically reappear in the inbox at some specified time in the future. With Apps Script you can extend Gmail yourself to add this functionality and a lot more.



The Solution

Here is the Apps Script code for a “Gmail Snooze” extension. First some configuration details. Setting these variables determines whether “unsnoozed” mail gets marked as unread, and whether it gets its own special label.
var MARK_UNREAD = false;

var ADD_UNSNOOZED_LABEL = false;

Setup

The “setup” function creates a new “Snooze” label in your Gmail, along with 7 sublabels for snoozing for different lengths of time, and potentially an “Unsnoozed” label. Running this function will also prompt you to authorize the script to use Gmail. This function makes use of the “getLabelName” helper function, which will be used by the code below.

Note: After you run the setup() function, the labels will be created in Gmail. However, you may have to refresh your Gmail window to see the labels.

function getLabelName(i) {

return "Snooze/Snooze " + i + " days";
}

function setup() {
// Create the labels we’ll need for snoozing
GmailApp.createLabel("Snooze");
for (var i = 1; i <= 7; ++i) {
GmailApp.createLabel(getLabelName(i));
}
if (ADD_UNSNOOZED_LABEL) {
GmailApp.createLabel("Unsnoozed");
}
}

Moving the Snooze Queue

The “moveSnoozes” function moves messages one day forward in the queue, so that messages snoozed for 6 days are now snoozed for 5 days, etc. Messages in the 1-day label are moved back into the inbox, and potentially marked as unread. To make this work automatically, you’ll need to create a nightly event trigger to run “moveSnoozes”. See the more detailed instructions at the bottom of the post.
function moveSnoozes() {

var oldLabel, newLabel, page;
for (var i = 1; i <= 7; ++i) {
newLabel = oldLabel;
oldLabel = GmailApp.getUserLabelByName(getLabelName(i));
page = null;
// Get threads in "pages" of 100 at a time
while(!page || page.length == 100) {
page = oldLabel.getThreads(0, 100);
if (page.length > 0) {
if (newLabel) {
// Move the threads into "today’s" label
newLabel.addToThreads(page);
} else {
// Unless it’s time to unsnooze it
GmailApp.moveThreadsToInbox(page);
if (MARK_UNREAD) {
GmailApp.markThreadsUnread(page);
}
if (ADD_UNSNOOZED_LABEL) {
GmailApp.getUserLabelByName("Unsnoozed")
.addToThreads(page);
}
}
// Move the threads out of "yesterday’s" label
oldLabel.removeFromThreads(page);
}
}
}
}

Using Snooze Label in Gmail

To "snooze" a thread, use Gmail’s “Move To” button to move the thread into the "Snooze for X days" label and archive it. Every night, threads will move up through one day of the queue, and at the appointed number of days they will reappear in your inbox, unarchived. If you want the messages to reappear as unread, just change “MARK_UNREAD” at the top to be “true”.

Because this is an Apps Script, you can edit the code any way you like. If you’d like different snooze times or for unsnoozed messages to get starred, you can easily change the code. And if you have an even better idea for how to use Apps Script to improve Gmail, you can post it to our Gallery (Script Editor > Share > Publish Project) to share with the world.

If you don't know how to setup a script, it's pretty simple. Create a new Google Spreadsheet, and choose "Script Editor" from the "Tools" menu. Paste in all of the code from above and then click the “Save” button and give it a name. In the dropdown labeled "Select a function to run," choose "setup" and click the blue run arrow to the left of it. This will ask you to authorize the script, and will create the necessary labels in your Gmail. Then go to the "Triggers" menu and choose "current script's triggers." Click the link to set up a new trigger, choosing the "moveSnoozes" function, a "time-driven" event, "day timer," and then "midnight to 1am." Click save and you are done.


Corey Goldfeder profile

Corey is a Google software engineer on the Apps Script Project, based in New York. He has previously worked on Similar Shape search for 3DWarehouse, and as a robotics researcher before joining Google.



Updated: 7/29/2011 to add additional instructions for refreshing the Gmail window after running the setup() function

We’re announcing the availability of the Changes feed in the Documents List API. This feed makes it easier to detect resources that have changed.

Currently, clients needing to sync resources between Google Docs and other systems or device often encounter a number of issues detecting changes to resources via the API. Clients typically query for all resources modified after a given date. This date is denoted by the ...
We’re announcing the availability of the Changes feed in the Documents List API. This feed makes it easier to detect resources that have changed.

Currently, clients needing to sync resources between Google Docs and other systems or device often encounter a number of issues detecting changes to resources via the API. Clients typically query for all resources modified after a given date. This date is denoted by the app:edited field of a resource entry. However, this field is not updated in all cases the client may care about, for instance if a resource is shared. In addition, querying for all resources modified after a given date does not produce entries for resources that have been deleted. This leads to very complex implementations of change detection by clients. These complex implementations usually have race conditions, and require a large volume of data to be exchanged with the API.

The Changes feed simplifies this process by providing resource entries only for changed resources. If a resource occurs in the Changes feed at all, the occurrence indicates a change to the resource. Once all changes are consumed, clients can store an identifier of the last change consumed. This identifier is called a changestamp. Future queries to the Changes feed with a changestamp will only return changes occurring after the given changestamp.

To start using the Changes feed, make an authorized HTTP GET request to the following URI:
https://docs.google.com/feeds/default/private/changes

The response from the API includes a Google Data API feed of resources that have changed:
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"
xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/"
xmlns:docs="http://schemas.google.com/docs/2007"
xmlns:gd="http://schemas.google.com/g/2005"
gd:etag="W/"DEEMQ3w8eyt7ImA9WhZUGUo."">
<docs:largestChangestamp>5635</docs:largestChangestamp>
<link rel="next" type="application/atom+xml"
href="...?start-index=5636"/>

<entry gd:etag="W/"DUcMRHg5cCt7ImA9WhZUGUo."">
<category scheme="http://schemas.google.com/g/2005#kind"
term="http://schemas.google.com/docs/2007#change"
label="change"/>
<title>Project tasks</title>
...
<docs:changestamp value="5623"/>
</entry>
...
</feed>

Fields shown in this example response are discussed in detail in the updated developer guide. Please use the forum for any questions about using the new feed.

Updates to the Java and Python client libraries are on the way, and will be announced in a separate blog post.



Russ Jorgensen LinkedIn

Russ Jorgensen joined Google in 2010 and is responsible for supporting and enhancing APIs which third-party applications can use to access and manage users' collections of Google Docs. Prior to working at Google, Russ was an embedded software engineer for 22 years at Bell Labs building telecommunications products such as PBXs and wireless communication systems.


Want to weigh in on this topic? Discuss on Buzz

Since the launch of the Google Tasks API many Google Apps domain administrators have asked us how to use the API with 2-legged OAuth 1.0 (2LO) for authorization. The process for using 2LO with the Tasks API is slightly different compared to using it for the Google Calendar API or the Google Contacts APIs, which makes it a little tricky if you are already accustomed to working with those.
Since the launch of the Google Tasks API many Google Apps domain administrators have asked us how to use the API with 2-legged OAuth 1.0 (2LO) for authorization. The process for using 2LO with the Tasks API is slightly different compared to using it for the Google Calendar API or the Google Contacts APIs, which makes it a little tricky if you are already accustomed to working with those.
  1. Any use of the Tasks API needs to reference a project in the APIs Console, as the Console is used to manage API quotas and other application settings (such as IP filters).
  2. The Tasks API needs to be explicitly enabled for your domain OAuth key and secret.
Note: 2-legged OAuth via the method described in this post and referenced documentation is available for Google Apps for Business and Google Apps for Education administrators, but is not available for administrators of the Free edition.

Referencing an APIs Console Project

The Tasks API needs to know which APIs Console project is sending requests to the API (so quota can be deducted, filters can be checked, etc.). To supply this information, you need to specify the API Key of your project within each request to the Tasks API-- even when using 2LO. This is done by specifying the API Key in a key URL query parameter.

    e.g.: https://www.googleapis.com/tasks/v1/users/username/lists?key=<API_KEY>

The Java client library can do this for you automatically if you specify it after initializing the Tasks service:
// Initializing the Tasks API service
Tasks service = new Tasks("2-LO Tasks Test", httpTransport, jsonFactory);
service.accessKey = API_KEY;

Enabling the Tasks API for your domain OAuth key and secret

Also, before your API requests will be successful, you will need to change a few things in your OAuth Consumer Key and Secret configuration. In the Manage OAuth domain key page available in the Google Apps Control Panel (under advanced tools), you will need to make sure that the option Enable this consumer key is checked and the option saying Allow access to all APIs is unchecked. This may sound counterintuitive, but this option will give you access to a specific set of APIs and is necessary to access the Tasks API.

Setting up the domain OAuth consumer key and secret

Then you will need to specify which APIs you want your domain OAuth key and secret to have access to. You will be able to do this in the Manage third party OAuth Client access page where you will need to list manually all the scopes that your domain key will have access to. For example for your token to have access to the Google Calendar API and the Google Tasks API use:
    e.g.: https://www.google.com/calendar/feeds/, https://www.googleapis.com/auth/tasks

You should then be all set to use 2LO with your Google Apps domain key and secret.

For a more detailed and step-by-step explanation with code samples on how to use 2LO if you are a Google Apps domain admin, I invite you to have a look at the newly published article: Using 2-Legged OAuth with Google Tasks API for Google Apps domain administrators.



Nicolas Garnier profile | twitter | events

Nicolas joined Google’s Developer Relations in 2008. Since then he's worked on commerce oriented products such as Google Checkout and Google Base. Currently, he is working on Google Apps with a focus on the Google Calendar API, the Google Contacts API, and the Tasks API. Before joining Google, Nicolas worked at Airbus and at the French Space Agency where he built web applications for scientific researchers.


Want to weigh in on this topic? Discuss on Buzz