2017 May 29 ~ June 4【泰國 素叻他尼 Surat Thani Thailand 🌊⛵️✈️👭】Ratchaprapa Dam, Koh Samui, Khao Sok National Park

圖片
My first trip to Surat Thani Thailand!

Ratchaprapa Dam is located in South Thailand and I highly recommend it as a destination if you are nature-loving traveller and considering traveling in Thailand.
We had wonderful two night stay at Keree Warin Resort which was a raft house accommodation on the lake. This lake is big, as I think it took around 30 minutes of travel by long tail boat to reach our resort.
We spent our time enjoying the breath-takingly beautiful views, swimming and canoeing around the vicinity of the raft house.It's really a great place to relax and have some quiet time in beautiful surrounding.


















Using Google Contact API to import Gmail Contacts in Rails App

The Google Contacts API allows users to retrieve their email contacts from a gmail account without giving a gmail password to the requesting site. This system allows social networking site users to invite friends and find existing users they know without exposing their gmail accounts to malicious site owners or poor security practices.

The Contacts API allows developers to create, read, update, and delete contacts using the Google Data protocol, based on AtomPub," the announcement says. "It also allows for incremental sync by supporting the 'updated-min' and 'showdeleted' parameters.

邀請朋友是現今的社群網站必備的功能,許多社群網站都允許讓用戶透過GMail,Hotmail,Yahoo! Mail等郵件服務匯入自己的聯絡人列表來邀請朋友。早期在ASP.Net,JAVA,PHP這些程式語言的典型作法是透過一些Library來實作匯入聯絡人清單,而在Ruby on Rails則有Contacts Gem這類的套件可以使用;但缺點是用戶必須在第三方網站所提供的表單上鍵入自己的GMail帳號密碼,如此一來安全性問題就產生了,儘管提供此類功能的網站都會在旁邊註明不會儲存用戶的帳號密碼,但是你真的信的過這些網站嗎?所幸Google Contacts API的推出解決了這個問題,下面我們將實作透過Google的Authsub驗證方式在Rails網站上從Google Contact API匯入聯絡人列表的功能。


下圖是Twitter匯入GMail聯絡人功能的畫面:


首先需要到Google的註冊頁面註冊並驗證你的網域名稱,這裡的callback_url必須對映到應用程式裡的方法,然後我們還要上傳一個X.509 certificate檔案:

https://www.google.com/accounts/ManageDomains

Registration for Web-Based Applications
http://code.google.com/apis/accounts/docs/RegistrationForWebAppsAuto.html

在*NIX和OS X平台上可以使用OpenSSL來產生RSA Keys和certificate(將www.example.com改成你的域名):

這個指令會產生rsakey.pem和rsacert.pem兩個檔案,將rsacert.pem上傳至Google的Manage Domains頁面,並將rsakey.pem放置到#{RAILS_ROOT}/config目錄下。

AuthSub in the Google Data Protocol Client Libraries
http://code.google.com/intl/zh-TW/apis/gdata/docs/auth/authsub.html

Authentication for Web Applications
http://code.google.com/intl/zh-TW/apis/accounts/docs/AuthForWebApps.html

之後當使用者按下"從GMail匯入聯絡人"連結後,使用者會被導向Google帳戶登入頁面(如果尚未登入),然後同意授權應用程式存取他們的GMail聯絡人資料,之後Google會傳回一個AuthSub Token給我們的應用程式。


授權應用程式存取Google聯絡人資料


下面是實作的Ruby程式碼:

首先我們在Google的Manage Domains頁面將callback_url設為http://www.example.com/authsub,因此我們可以在/config/routes.rb裡面添加路徑映射:

map.connect 'authsub', :controller => 'gmail_contacts', :action => 'authsub'

接下來新增一個GmailContacts Controller 內容如下:

然後在Application Controller添加下面內容:

接著在config/initializers目錄下建立一個google.rb 內容如下:

最後編輯/app/views/gmail_contacts/import.html.erb 內容如下:


現在我們已經可以成功從GMail匯入使用者的聯絡人列表,而且使用者並不需要在我們的網站上輸入任何GMail帳號密碼,所有的驗證過程都是在Google網站上以SSL安全連線來完成。接下來只要將這個部份整合到你網站上的邀請朋友功能,就能夠讓使用者選擇要發送邀請給哪些GMail上的聯絡人了!

參考資料:

Google Contacts API
http://code.google.com/intl/zh-TW/apis/contacts/

Contacts Gem at Github
http://github.com/cardmagic/contacts

ricardoalmeida / contacts_rails at Github
http://github.com/ricardoalmeida/contacts_rails

Google Data on Rails
http://code.google.com/intl/zh-TW/apis/gdata/articles/gdata_on_rails.html

Using Google OAuth in Ruby on Rails Sites
http://www.manu-j.com/blog/add-google-oauth-ruby-on-rails-sites/214/

Import Gmail Contacts using Ruby on Rails
http://blog.adsdevshop.com/2008/04/18/import-gmail-contacts-using-ruby-on-rails/

A Little Help on Importing Gmail Contacts using Ruby on Rails
http://www.theirishpenguin.com/2008/06/25/a-little-help-on-importing-gmail-contacts-using-ruby-on-rails/

Import contacts list in rails
http://blog.brijeshshah.com/import-contacts-list-in-rails/

blackbook gem (Contact Importer gem for Ruby on Rails)
http://saravani.wordpress.com/2009/03/13/blackbook-gem-contact-importer/

Fetching Cotacts From Gmail, Yahoo And Hotmail
http://puneetitengineer.wordpress.com/2008/09/26/fetching-cotacts-from-gmail-yahoo-and-hotmail/


Here is a (incomplete) list of pages with documentation for different open apis:

Hotmail: http://dev.live.com/contacts/
Gmail: http://googledataapis.blogspot.com/2008/03/3-2-1-contact-api-has-landed.html
Yahoo: http://developer.yahoo.com/social/contacts/ , http://developer.yahoo.com/addressbook/

熱門文章

[轉載] 洛克菲勒寫給兒子的38封信(全文)

September, 2012 白姑大山二天一夜~其實沒那麼累,只是路途遙遠

【清邁之旅 Part 1|Exploring Doi Suthep-Pui National Park】The 6 Day Itinerary To Explore Chiang Mai And Northern Thailand's Mountains

2013.5.25~26【新阿溪縱走】眠月線鐵道線探勘。順登松山、萬歲山、小笠原山、對高岳

2018, Sep 21【嘉義。阿里山】特富野古道健行。鐵道、迷霧、森林(Tefuye Historical Trail)

2018 May 5~6【宜蘭】南方澳漁港~豆腐岬~朝陽國家步道~南澳觀音海岸~礁溪福哥石窯雞

FbGraph + OmniAuth + Facebook Graph API on Rails application

文章列表

聯絡我

名稱

以電子郵件傳送 *

訊息 *