-
Notifications
You must be signed in to change notification settings - Fork 53
DeskSMS API
#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 Python script that will retrieve the user's inbox using OAuth as an authorization mechanism.
Note that the OAuth Authorization Header must be used. OAuth in the query string or post parameters is not supported.
##ClientLogin/Cookies
USERNAME=your_email@gmail.com
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/your_email@gmail.com/sms");
String ascidCookie = settings.getString("Cookie");
get.setHeader("Cookie", ascidCookie);
get.setHeader("X-Same-Domain", "1"); // XSRF
HttpResponse response = client.execute(get);
#Web Service Endpoints
Woot! You are successfully authorizing against the web service endpoints! Here's how you can get your data.
All requests come with the following prefix/format:
https://desksms.appspot.com/api/v1/your_email@gmail.com/<bucket>
###SMS Bucket (messages you have sent and received):
https://desksms.appspot.com/api/v1/your_email@gmail.com/sms
Results in:
{
"data": [{
"name": "Koushik Dutta",
"read": false,
"number": "+15555555555",
"thread_id": 5,
"date": 1311458362799,
"message": "Hello World!",
"type": "incoming",
"id": 217
},
{
"name": "Koushik Dutta",
"read": false,
"number": "+15555555555",
"thread_id": 5,
"date": 1311458362798,
"message": "First post!",
"type": "outgoing",
"id": 216
}]
}
###Outbox Bucket (messages that are pending to be proxied and sent by the phone):
https://desksms.appspot.com/api/v1/your_email@gmail.com/sms