Oct 21~24, 2023【晚秋の贅沢な山旅 PART②】黒部峽谷♡下之廊下|日本北阿爾卑斯山秘境健行+野營+秘湯溫泉 DAY 1(黒部水壩〜下之廊下〜阿曾原溫泉)

圖片
今天是這趟四天三夜秋季山旅的第二天,昨天在信濃大町悠閒度過了半天,今天終於要進入黑部峽谷山區了。原本是預計早上6點15分,要從信濃大町車站前,乘坐第一班巴士前往 扇沢 ,但是旅館客房太溫暖,不小心睡過頭,等到自然醒時,看了手機已經早上6點了。 這時就算再怎麼快速收拾背包衝到車站也趕不上6點15分的巴士了。雖然還有下一班巴士可以搭,但是今天的路程有點遠,得走上20公里,加上紅葉季節,如果太晚抵達露營場,可能會找不到位置紮營,所以我想還是儘早出發比較好。幸好車站前有計程車可以利用,只是必須多花幾千塊日幣消災就是了。 在觀光季節,最早一班由 扇沢 開往 黒部ダム ( 黑部水壩 )的巴士是早上7點30分發車,所以只要需抓個50分鐘的乘車跟買票時間,大概早上6點40分左右,從大町車站前搭上計程車就沒問題了。 洗漱完畢,整理好背包後,將房間鑰匙放回旅館櫃檯的籃子裡,然後走路到車站前面,叫一輛計程車前往 扇沢 (車資大約8000日幣上下)。走在路上可以看見遠處三千公尺級的高山,都已經覆上了新雪,預告著今年的雪季即將到來。 早上7點左右抵達 扇沢 ,買了一張前往 黑部水壩 的單程電氣巴士車票(1,800日幣),然後將登山計畫書投遞進箱子裡,走上二樓排隊等待搭車。果然不愧是紅葉季節,車站二樓裡面,整整四排的排隊區,已經排滿了登山客和觀光客。 扇沢 其實就是 立山黑部阿爾卑斯路線 的長野側起點,是觀光客很喜歡造訪的地方,只是一般觀光客不會曉得,站在黑部水壩頂部欣賞放水時,在那 日本規模第一 的水壩後方之溪谷深處,竟然隱藏著一條少為人知的登山步道。 相關參考連結 下ノ廊下を含む活動日記一覧(YAMAP) 登山ルート情報 - 阿曽原温泉小屋 立山黒部アルペンルート|公式サイト アルピコ交通|路線バス 扇沢線 くろよん(黒部ダム)ーその手に未来をー|関西電力 2021年の番組~最後の秘境・黒部源流紀行【小椋久美子が黒部川の“最初の一滴”を目指す旅】 【下の廊下】黒部峡谷の断崖絶壁を命懸けで歩く(前編) 【下の廊下】落ちたら終わりの絶景登山道(後編) 【テント泊登山】断崖絶壁30kmの道、黒部峡谷の歴史を歩く|旧日電歩道-下ノ廊下-水平歩道 【全篇】『黒部峡谷探検』1927年|「フィルムは記録する」より ‘Film IS a Document: NFAJ Historic Film Porta...

Integrating Facebook Connect with your Rails Applications

Facebook Connect is a set of APIs from Facebook that enable Facebook members to log onto third-party websites, applications, mobile devices and gaming systems with their Facebook identity. While logged in, users can connect with friends via these mediums and post information and updates to their Facebook profile. Developers can use these services to help their users connect and share with their Facebook friends on and off of Facebook and increase engagement for their website or application.

Originally unveiled during Facebook’s developer conference, F8, in July 2008, Facebook Connect became generally available in December 2008. According to an article from The New York Times, "Some say the services are representative of surprising new thinking in Silicon Valley. Instead of trying to hoard information about their users, the Internet companies (including Facebook, Google, MySpace and Twitter) all share at least some of that data so people do not have to enter the same identifying information again and again on different sites."

Windows Live服務整合Facebook Connect功能的畫面:


Facebook Connect是Facebook在2008年推出的功能,推出後馬上被許多大中小型網站所使用。透過Facebook Connect,用戶將可以在整個網路上使用Facebook的身份驗證資料,包括使用Facebook帳戶登入/註冊第三方網站,以及在其他網站分享他們的頭像照片、名稱、照片、朋友、群組、活動以及其他的資訊。這個是以前所做的東西,但Facebook已經在今年推出了新版的Open Graph API,若打算實作這個部份的話,建議還是使用新版的API會比較可靠!

Facebook Connect
http://developers.facebook.com/connect.php

Facebook Platform Wiki
http://en.wikipedia.org/wiki/Facebook_Platform


下面是實作Facebook Connect in Rails Application的過程:

1.首先我們需要給Rails project安裝Facebooker Plugin:
$ script/plugin install http://github.com/mmangino/facebooker/tree/master
安裝新版的facebooker插件必須將Rails升級到2.2版本以上.

2.你需要在Facebook註冊一個Developer測試帳戶,或是從下面網址讓你現有的Facebook帳戶成為Facebook Platform Developer Test Accounts(開發應用程式用的測試帳戶):
http://www.facebook.com/developers/become_test_account.php

登入Facebook Developer頁面註冊你的應用程式:
http://www.facebook.com/developers

步驟1. Add the Developer Application.
步驟2. Create a New Facebook Application.
步驟3. Update the Facebook Application settings to point to your publicly available host.

Example settings(假設域名是:http://www.example.com):

Authentication Tab:
  Enter Post-Authorize Callback URL, e.g. http://www.example.com/fb/post_authorize
  Canvas Tab:
Enter Canvas Page URL, e.g. run_example_com
Enter Canvas Callback URL, e.g. http://www.example.com/fb/connect
  Connect Tab:
Enter Connect URL, http://www.example.com/fb/connect
  Advanced Tab:
Set Application Type as Web.

將facebooker plugin裡的facebooker.yml文件放在/config目錄下,並編輯其內容:

Set api_key, secret_key, canvas_page_name (copy the last part of the Canvas Page URL from the Canvas tab), callback_url (that's Canvas Callback URL from FB settings), and set set_asset_host_to_callback_url to false.

下面是一個facebooker.yml範例內容:

然後執行xd_receiver generator來產生cross domain scripting bridge,用來讓你的應用程式可以和Facebook溝通:

$ script/generate xd_receiver

預設之下它會在/public目錄下建立xd_receiver.html和xd_receiver_ssl.html兩個檔案,我們將它們放置到/public/fb/connect目錄下,因為這個路徑會對映到我們稍候建立的FbController的connect方法中,而我們也會在/config/route.rb中定義這個路徑。

接下來將facebooker plugin目錄下的facebooker.js複製到/public/javascript目錄下,並新增一個facebook_require.js檔案,內容如下:

編輯/public/javascript/application.js新增下面內容:

編輯app/vews/layout/application.html.erb新增內容:

我們還要在適當的樣板中新增一個藉由Facebook Session登入的"登出"連結,用來區別和一般帳戶登入的不同,點擊'從Facebook登出'將會刪除現階段的Facebook Session並將使用者導向/logout來登出網站

編輯/config/environment.rb,新增環境變數:


典型的方式是使用網站資料庫裡現有的Users資料表中的DB Record來和Facebook帳戶整合, 我們將在users table中新增fb_uid(facebook uid)和email_hash(to contain a hashed version of the user's email address)欄位。

A typical case for integration is to add Facebook Connect as an alternative way of authenticating for existing users. To achieve this, add fields fb_uid (facebook uid) and email_hash (to contain a hashed version of the user's email address) to the users table.

接下來新增一個Run Publisher模型:
$ script/generate model RunPublisher

Publishing is handled by the RunPublisher class in app/models/run_publisher.rb. Every feed template needs to be registered with Facebook before it can be used and this is done via migrations.

編輯/app/models/run_publisher.rb的內容:

然後建立新的Database遷移檔:
$ script/generate migration CreateFacebookTemplates

編輯/db/migrate/xxxxx_create_facebook_templates.rb遷移檔內容:

然後還需要建立一個遷移檔,在users資料表添加一些新的欄位:
$script/generate migration AddFacebookConnectToUsers

編輯/db/migrate/xxxxx_add_facebook_connect_to_users.rb內容:

最後執行rake db:migrate建立資料表!

接下來編輯/config/route.rb新增下面的路徑映射:

在/bin目錄下新增fb_preconnect.rb內容如下:

接下來在/bin目錄下新增register_templates.rb內容如下:

現在我們可以執行 script bin/fb_preconnect.rb 來預先連結資料庫中的所有使用者,這樣將能夠讓Facebook知道我們資料庫中的使用者可能會在將來使用Facebook Connect連結他們的帳戶。Facebook會預先連結使用者的 email_hash 來配對帳號。若不執行preconnect動作,Facebook將不會去包含 email hash 的值,將來使用者過Facebook Connect連結時,將需要輸入他們的Email地址!

稍候我們在/app/models/user.rb中建立的after_create callback可以讓將來任何新建立的使用者帳號都會自動和Facebook去做預先連結。

藉由Users資料表中的 fb_uid 欄位,使用者將可以透過正常的登入機制(帳號/密碼) 或是Facebook Connect 按鈕來登入,而我們會在/app/controllers/fb_connect_controller.rb建立Facebook Connect主要的驗證機制。


現在新增一個FBConnect Controller並編輯其內容如下:
$ script/generate controller FbConnect

下面是我們的FbConnect Controller處理Facebook Session Login的簡單流程圖:


在Application Controller新增方法,用來處理Facebook Session以及Session Expired:

然後需要修改用來處理登入驗證機制的/lib/login_system.rb的內容:

接下來要修改/app/controllers/account_controller.rb中用來處理登出的logout方法:

登出Rails網站並同時登出Facebook


接下來修改Users Controller中的New和Create方法(這是用來建立使用者的):

在new方法添加這些過濾內容是為了防止使用者直接在網址攔輸入fb_user=1的參數來欺騙應用程式,正確的作法是必須透過Application_Controller中的facebook_user方法來驗證使用者是真正透過Facebook Session來註冊帳號。我們同樣也可以在create方法中添加這條過濾!

然後編輯User Model內容,修改password_required?方法:

上面的before_update是為了在使用者變更Email地址之後,建立新的Facebook Session和變更email_hash的值。其中的email_changed?是在Rails 2.1版本之後開始內建的方法,可以直接調用

接下來修改/app/views/users/new.html.erb視圖的內容:

然後修改/app/views/users/edit.html.erb視圖,編輯密碼修改的欄位部份:

並在users的edit和show視圖中新增下面的判斷內容:

然後在/app/views/shared目錄下建立_fbconnect_button.html.erb和_fbpublish.html.erb兩個樣板檔:

其中_fbconnect_button.html.erb內容如下:

另外_fbpublish.html.erb內容如下:

然後將貼到需要添加Facebook登入按鈕的視圖頁面即可(如首頁,Signup頁面和Login頁面)


接下來我們可以編輯相關的視圖,讓透過Facebook Session登入的使用者可以在頁面上直接顯示他們的Facebook頭像圖片和Facebook用戶名稱(點擊圖片可以連結至他們的Facebook頁面),而不再是我們網站上的頭像圖片。

PS.從這邊開始的部份都是我自己的Rails Project的內容,看不懂的請不要亂複製到你的Project,我這裡只是提供一個概念作為參考!

首先修改users_helper.rb中的user_link方法:

然後修改users/_status_update.html.erb的視圖內容,這是使用者首頁的狀態發佈器。

接著修改users/_current_status.html.erb視圖:

最後將下面內容加到/app/controllers/users/status_update_controller.rb的Create方法中:



另外我們還可以修改/app/views/wall_comments底下的_form.html.erb和_comment.html.erb視圖,讓透過Facebook Session登入的使用者可以在Profile頁面的塗鴉牆看到自己的Facebook頭像和名字:

修改/app/views/wall_comments/_form.html.erb視圖:

修改/app/views/wall_comments/_comment.html.erb視圖:

OK搞定了!而其他需要顯示Facebook頭像的頁面也可以用同樣的邏輯來作修改,非常簡單!


接下來我們要將Rails網站裡面的一些功能和Facebook做進一步的整合,首先我們要將使用者首頁的狀態更新和Facebook塗鴉牆整合,讓使用者在網站上更新狀態時,訊息可以同時發佈到使用者的Facebook塗鴉牆上。

首先在users/status_update_controller.rb中新增一個fbpublish方法:

然後編輯/public/javascript/application.js新增下面的內容,其中的Ajax Request路徑會指向Users::StatusUpdatesController中的fbpublish方法,它會執行一些Ajax動作:

接著我們在users/status_update_controller.rb的Create方法中添加下面的內容:

然後在建立/app/views/shared目錄下建立_fbpublish.html.erb樣板:

並修改users/_status_update.html.erb樣板內容:

另外,視圖中jQuery的部份也需要修改:


使用者尚未授權Facebook帳戶可以透過第三方網站張貼內容至Facebook塗鴉牆


授權Facebook帳戶畫面,授權之後我們的應用程式會去呼叫Users::StatusUpdatesController中的fbpublish方法執行Ajax動作。


已授權Facebook帳戶可以從第三方網站張貼內容至Facebook塗鴉牆


訊息已透過我們的應用程式發佈到使用者的Facebook塗鴉牆上


最後我們可以在使用者的首頁和個人檔案頁面顯示該使用者Facebook帳號上的朋友,首先在首頁和個人檔案頁面載入部份樣板:

最後建立/app/views/shared/_fbfriends.html.erb樣板:




下面是一些Facebook Connect的相關資源以及Tutorial:

Facebook Connect on Facebook Developers
http://developers.facebook.com/connect.php

Using Ruby on Rails with Facebook Platform
http://wiki.developers.facebook.com/index.php/Using_Ruby_on_Rails_with_Facebook_Platform

Facebooker Tutorial
http://apps.facebook.com/facebooker_tutorial/

Tutorial for restful_authentication on Rails with Facebook Connect in 15 minutes
http://www.madebymany.co.uk/tutorial-for-restful_authentication-on-rails-with-facebook-connect-in-15-minutes-00523

Tutorial on developing a Facebook platform application with Ruby On Rails
http://www.liverail.net/articles/2007/6/29/tutorial-on-developing-a-facebook-platform-application-with-ruby-on-rails

Integrating Facebook Connect with Rails Applications
http://nws.applicake.com/blog/index.php/2009/07/02/integrating-facebook-connect-with-rails-applications/

Using Facebooker to make a Rails site with Facebook Connect (Part 1)
http://blog.moove-it.com/using-facebooker-to-make-a-rails-site-with-facebook-connect-part-1/

Using Facebooker to make a Rails site with Facebook Connect (Part 2)
http://blog.moove-it.com/using-facebooker-to-make-a-rails-site-with-facebook-connect-part-2/

Using Facebooker to make a Rails site with Facebook Connect (Part 3)
http://blog.moove-it.com/using-facebooker-to-make-a-rails-site-with-facebook-connect-part-3/

Rails app on Facebook Connect
http://www.rubyflow.com/items/1322

Star in a Porno with Facebook Connect and Rails
http://spongetech.wordpress.com/2008/11/17/star-in-a-porno-with-facebook-connect-and-rails/

How to Facebook-Connect a Rails app
http://passthehash.com/hash/2009/05/how-to-facebook-connect-your-rails-app.html

Getting Started with Facebooker
http://www.pathf.com/blogs/2008/07/getting-started-with-facebooker/

熱門文章

2019 Aug 16~18【福建南平】中國世界遺產~福建武夷山遊記。登天遊峰、臨九曲溪、品大紅袍

2019, July 7~8【中國山東】老司機帶你攀登72位古代帝王曾登臨朝拜,以五嶽獨尊名揚天下的泰山(歷史典故+遊覽路線+遊記+照片)

Sep 2024 晚夏的黑部源流4泊5日山旅 PART ①【溪流登攀&溫泉三昧】赤木沢~五郎沢~祖父沢遡行&雲ノ平~高天原~裏銀座縱走(旅途的開始)

Sep 2025【苗栗大湖】關刀山脈|出關古道(聖關段)登關刀山(薑麻園起登O繞一圈)

Jan 2025【苗栗泰安】泰安警光山莊泡湯&沐藏料理所X海龍王|彰化板前料理 ♨️🍁🥢🍲

Oct 2025【新竹尖石】魯壁山~東穗山~竹60鄉道O形健行|入門中級山|原始林相頗優美

Sep, 2021【苗栗南庄】蓬萊林道Off Road小試|雨後很爛很濕滑|二傳低底盤車勿輕易嘗試

Oct 21~24, 2023【晚秋の贅沢な山旅 PART②】黒部峽谷♡下之廊下|日本北阿爾卑斯山秘境健行+野營+秘湯溫泉 DAY 1(黒部水壩〜下之廊下〜阿曾原溫泉)

Jul 2025【台中中區】瓦庫燒肉 WOW COOL YAKINIKU|台中車站附近的紅磚老宅燒肉餐廳

Mar 12, 2022【重機一日遊】走北橫至宜蘭,經梨山、武嶺下埔里,再走台三線回桃園|16小時的半圈環島

文章列表

Contact

名稱

以電子郵件傳送 *

訊息 *