無法從 Google Apps 腳本連接到 Google Latitude API (Can't connect to Google Latitude API from Google Apps Script)


問題描述

無法從 Google Apps 腳本連接到 Google Latitude API (Can't connect to Google Latitude API from Google Apps Script)

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. 

‑‑‑‑‑

參考解法

方法 1:

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. 

(by ictdynamic.beArun Nagarajan)

參考文件

  1. Can't connect to Google Latitude API from Google Apps Script (CC BY‑SA 3.0/4.0)

#google-latitude #google-apps-script






相關問題

Otentikasi permanen Google Latitude API untuk akun tertentu (Google Latitude API permanent auth for specific account)

無法從 Google Apps 腳本連接到 Google Latitude API (Can't connect to Google Latitude API from Google Apps Script)

如何在谷歌地圖API中獲取高速公路和道路的緯度和經度 (How to get Latitude and Longitude of highways and roads in Google maps API)

如何修復谷歌地圖上的標記並移動地圖? (How to fix marker on google map and move map?)

使用 Google Latitude API 獲取朋友的位置 (Using Google Latitude API to get friends' locations)

尋找我和朋友之間最近的距離 (Finding nearest distance between me and friends)







留言討論