Reputation: 23
Google Apps Script currently only supports OAuth 1.0a and the Google Latitude API only supports OAuth2 so it seems clear you cannot use the Google Latitude API from Google Apps Script at the moment.
But is there a planning on when the 2 APIs will be integrated? Since I'm quite in favor of storing my data (including addresses) in a google app spreadsheet it seems making sense to me to access them with Google apps script and to apply some additional logic like distance calculations.
I'm aware of the Google Maps Javascript Api V3 but as such, I would loose the flexibility to reuse my google app spreadsheet.
Upvotes: 2
Views: 543
Reputation: 5655
oAuth 2 is very possible in Apps Script. However, it does require a bit more hand holding of the flow (unlike the built in oAuth1.0a). There are plans to improve that in the future but for now this will work.
The trick is to use the oAuth 2 Web Server flow. Take a look at this example that grabs your profile information (Latitude has a similar REST API).
https://gist.github.com/4079885
There is a published version of this script here -
https://script.google.com/macros/s/AKfycby3gHf7vlIsfOOa9C27z9kVE79DybcuJHtEnNZqT5G8LumszQG3/exec
This should basically be able to read some basic profile info. There isnt much in the way to logout, error handling.. but hopefully this code sample works for you. Specifically check out - getAndStoreAccessToken()
To work within a Spreadsheet, open the link to getURLForAuthorization()
from a Spreadsheet.show dialog and then get the token and grab data.
I hope to tutorialze this some more and provide some integration samples with Spreadsheets directly as well.
Upvotes: 2