Oct 21~24, 2023【晚秋の贅沢な山旅 PART①】從名古屋搭車至長野|在北阿爾卑斯山麓的文藝小鎮信濃大町散步、品嚐美味的炸豬排定食和咖啡

圖片
今年10月下旬,趁著深秋季節,請了兩天特休假,飛往日本中部北陸地區,探訪兩處幾年前就想去的地方。其中一處是位於 新潟縣 和 長野縣 交界處的日本百名山【 雨飾山(Mt. Amakazari) 】,10月中下旬的紅葉全盛期,是造訪這座 日本百名山 的最佳時間點,且因爲海拔高度只有兩千公尺左右,相比三千公尺級的 北阿爾卑斯山脈 ,這裡的積雪時間略晚一些。即使到了10月下旬,只要沒有強烈冷氣團,沒有雪季登山裝備也還是能夠登頂。 另一處則是少為人知的 秋季限定路線 ,黑部峽谷【 下ノ廊下 】(下之廊下),這個地方除非是登山客,不然連一般日本人都不太普遍聽過。 下之廊下 位於 黑部大峽谷 的北部地區,因為靠近 日北海 ,冬季這裡是豪雪地帶,只有從每年9月下旬登山道的積雪完全融化後,到11月上旬左右,山區再次降雪之前,大約一個月左右的時間可以通行。 據聞2022年因融雪較慢,能通行的時間只有短短兩週,而今年則是融雪較早,9月中旬就全面開通了。前陣子9月來日本爬山時,原本就有計畫要來這裡,不過後來因為一些原因,就提前返國了。最終等到10月下旬的深秋,也盼到了連續幾日都是好天氣的日子,終於如願前來造訪! 每年10月下旬至11月上旬,是 下ノ廊下 的紅葉最盛期,也是登山客最多、最混雜的時期。其壯闊的峽谷絕景、險峻的斷崖峭壁、遠方覆上初雪的山岳景致、迷人的三段紅葉、還有途中有著被稱為「 秘湯中的秘湯 」的【 阿曾原溫泉 】,加上 一年之中只有極短時間可通行的條件 ,使得黑部峽谷【 下ノ廊下 】成為喜愛山岳之人無不嚮往造訪的山岳秘境。 黑部峽谷自古就是人跡罕至的秘境而廣為人知,江戶時代也因加賀藩的國境警備和森林管理而禁止進入,僅黑部奧山廻御用之役人在此巡邏。明治時代以後對外開放,黑部也成為眾多登山家的目標。其中,冠松次郎因致力探索峽谷而有「黑部之父」的稱號。 黑部峽谷以黑部湖(黑部水壩)為境,可分為 下之廊下 、 上之廊下 ,以及 奧之廊下 。「廊下」是山岳用語,意指「 絕壁之間的深谷 」,而「下之廊下」相當於黑部峽谷的心臟地帶,花崗岩岩壁間的激流從下游起形成白龍峽、十字峽、S字峽等景點。 由於行走於距離河面數十至上百公尺的斷崖峭壁間,許多區間寬度又十分窄小,是有點危險的路線, 每年都有人在這裡不慎摔死 (今年也不例外)。 日本國土地理院地圖(下之廊下) 據說今年秋天日本的下雨天數特別多

FbGraph + OmniAuth + Facebook Graph API on Rails application

OAuth is often described as a 'valet key for the web'. In the same way as a valet key gives restricted access to a car, allowing the valet to drive it but not open the trunk or glovebox, OAuth allows a client application restricted access to your data at a resource server via tokens issued by an authorization server in response to your access grant.

Facebook Platform uses the OAuth 2.0 protocol for authentication and authorization. Suppose your Rails application allows users to share content with their Facebook friends. To support this, a connection needs to be established between a user's local account and her Facebook account. Once established, a Facebook instance can be obtained and used to post content to the user's wall. The basic idea is to store the access_token during an OAuth2 login process and later on use the token to fetch more data.

The last days I was working on letting user sign-up/sign-in using Facebook account. I'm planning to integrate some social features into my ongoing Rails project. Previously I was working with Facebooker, an awesome Rails plugin that did a great job for my previous project, however it seemed not support the latest Facebook Graph API. Thought I found a new solution.

OmniAuth is an open source project which provides support for many of the main providers out there: twitter, facebook, foursquare, and many more. In addition, OmniAuth is designed in such a way that it is very easy to implement custom strategies---interchangable logic which encapsulates the steps required to successfully authenticate with an Oauth2 provider.

OmniAuth relies on the request and callback sequence as defined in OAuth2 specification. OmniAuth extracts away a lot of the complexity of working with OAuth, so we can skip all of that information and focus on just what we need to. The diagram below depicts how OmniAuth handles the request and callback sequence:


The request phase of the OAuth dance typically redirects to a providers website which prompts the user to enter their credentials with the provider calling back to Omniauth with a success or failure message.

There is a couple of great screencasts on how to integrate Omniauth to Devise using Rails 3 and allow Facebook, Twitter, etc. authentications. In this post, I'm going to show you how to connect to the Facebook platform using FbGraph along with Omniauth to retrieve a list of records and post message to the facebook wall via its Graph API. For this example, I'm using Rails 2.3.8 on my Mac. But I strongly encourage you to start with Rails 3.

First, we would need a migration to store a permanent Facebook token for offline access:
$ script/generate migration AddFacebookTokenToUsers


Add the following to your config/environment.rb

Next, in your initializer, usually config/initializer/omniauth.rb, request additional permissions, we need to tell Omniauth to retrieve more Facebook permissions in order to have offline access, Wall, etc. You can define the ones you need from Facebook permissions API pages, but here is my setting:

If you get this error message when you're trying to run your Rails server: 
WARNING: Nokogiri was built against LibXML version 2.7.7, but has dynamically loaded 2.7.8
The problem was most likely bad library management, if you don't have libxml2 in the Cellar directory on OSX, you can install it to this using homebrew:


Now, lets get to the application code changes. In the application controller we define the facebook_user like this:


In the routes.rb we add following routes:


Next, edit your fb_oauth_controller.rb add the callback method:


Callback is the action that is called after the authorization. The access_token is not restricted with time unless Facebook changes their policy and make them expire after a particular period of time, and is used later for interacting with Facebook.. To understand how it all works, read about Facebook permissions, the Graph API. The /auth/facebook url is invoked first. This redirects the user to Facebook where the user gets the permission prompt, to allow your application to access the users information. If everything works you should have the full authentication workflow going!



You can also use this URL to get a permanent access_token:


Facebook uses the OAuth 2.0 protocol for user authentication and application authorization. Following are the steps required to obtain an access token:

(a) Redirect the user to https://graph.facebook.com/oauth/authorize and pass the application id and post authorize callback URL as parameters to this API.
(b) User enters their credential in the above Facebook URL and after successfully authorizing the application, Facebook would redirect the user to the authorize callback url along with a verification string in the argument code, which can be exchanged for an OAuth access token.
(c) Generate an access token using the above verification code by fetching https://graph.facebook.com/oauth/access_token

Once the access token is obtained, all further communications to Facebook will only require this token instead of the user’s credentials. 


You can modify the callback method to integrate Facebook connect with your authentication system (Allow your users to sign up/sign in with their Facebook account). See the example below:


Now the application retrieves email and also you have an access to Facebook Graph API. For instance, to post something on Facebook wall you can:




Enjoy! hope this helps you :)


熱門文章

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

May 2023【台中南屯】地雷店食記|森鐵板燒|用餐體驗差,價格超貴卻豪無價值。小心別踩雷!!!

Jun 24~25, 2022【南橫三星】庫哈諾辛山+【南臺首嶽】關山(進涇橋登山口)|2天1夜野營登山

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

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

Sep, 2023【桃園龍潭】輕鬆登頂石門山欣賞石門水庫湖光山色|景春步道+小竹坑古道O型路線午後健行

Nov 20, 2022【新北烏來】信賢步道健行~輕鬆好走的生態步道,還可順遊內洞森林遊樂區

Feb 2023【台中和平】裡冷林道Off Road單車野營~順登谷關七雄之首八仙山!單車+野營+登山,三個願望一次滿足

May 2023【台中潭子】新田登山步道1+3+5號步道O型環走|噴汗爬1063木棧階梯、順登小百岳聚興山

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

文章列表

Contact

名稱

以電子郵件傳送 *

訊息 *