Skip to content
koush edited this page Jul 24, 2011 · 30 revisions

##Authorization To use the API, all your requests must be come with a form of authorization for your Google Account.
There are two ways you can authorize: ClientLogin/Cookies or OAuth.

OAuth is the preferred method of authorization, as it does not require that the user enter their username and password in your application of website.

#OAuth Here is a https://github.com/ClockworkMod/desksms/blob/gh-pages/oauth/example.py that will retrieve the user's inbox using OAuth as an authorization mechanism.
Note that the http://oauth.net/core/1.0/#auth_header must be used. OAuth in the query string or post parameters is not supported.

#ClientLogin/Cookies

[email protected]
PASSWORD=swordfish
# First, let's get an auth token
curl -d "accountType=HOSTED_OR_GOOGLE&Email=$USERNAME&Passwd=$PASSWORD&service=ah&source=desksms" https://www.google.com/accounts/ClientLogin

This will print the following credentials:

SID=DQAAALoAAAB...........................................................................
LSID=DQAAALwAAADfRf9M...........................................................................
Auth=DQAAAL0AAADfRf9MqXN9aV...........................................................................

You are interesed in the Auth portion. Let's grab that entire line and conveniently set it as an environment variable.

Auth=DQAAAL0AAADfRf9MqXN9aV...........................................................................

Let's get a Cookie for this Auth token. The cookie will be in the header of the response, so we can just pipe the response body (which is unncessary) to /dev/null:

curl -v "https://desksms.appspot.com/_ah/login?auth=$Auth" > /dev/null

There should be a lot of spew due to the verbose curl output, but in there, you should see:

< Set-Cookie: SACSID=AJKiYcEj................................................................; expires=Sun, 24-Jul-2011 23:57:

The bit that you want to save for your application is simply everything before the semicolon, ";":

SACSID=AJKiYcEj................................................................

So, if you wanted to retrieve your SMS history using curl:

# set the cookie as a convenient environment variable
SACSID=AJKiYcEj................................................................
curl -H "Cookie: SACSID=$SACSID" https://desksms.appspot.com/api/v1/user/$USERNAME/sms

Or, for example, using Java:

HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet("https://desksms.appspot.com/api/v1/user/[email protected]/sms");
String ascidCookie = settings.getString("Cookie");
get.setHeader("Cookie", ascidCookie);
get.setHeader("X-Same-Domain", "1"); // XSRF
HttpResponse response = client.execute(get);
Clone this wiki locally