Jan 2025【日本東北】溫泉三昧之旅④ 在大雪飄落的雪國,追尋秘湯之宿與極上美食(福島~探訪豬苗代湖、磐梯山、會津若松城&千年古湯 蘆之牧溫泉)

圖片
今早6點半起床,準備7點去使用昨天事先預約好的貸切露天風呂,這是「御宿萬葉亭」的名物,每一組住宿客人可以免費使用40分鐘。庭園裡的半露天的風呂,有兩個浴缸,一次只能容納最多三個人同時使用,左邊圓形的浴缸水溫很高、右邊橢圓形的浴缸水溫較低。雖然旅館裡面也有露天浴池,但是早晨享受一下這個庭園裡的露天風呂,也是一種特別的享受。 細密的雪花輕輕飄落,落在庭園的樹木和灌木叢上,覆蓋上一層柔軟的白色。原本翠綠的植物,此刻都披上了銀裝,枝條低垂,彷彿在向雪國的冬天致敬。 遠處的樹林,也都被白雪覆蓋,形成一片靜謐的雪白世界。偶爾,一陣微風吹過,樹枝輕輕搖晃,雪花便如柳絮般飄落,在空中舞動。我泡在熱氣氤氳的溫泉浴池中,早晨的寒意逐漸消散,而欣賞著這如詩如畫的雪景,身心都得到了徹底的放鬆。 聽聞中之澤溫泉的溫泉源自百年前的一場驚天動地的災難,根據我在旅館裡看到的白板資料,那場災難就發生在西元1888年,也就是明治21年的7月15日。某天的夏日清晨,本應是寧靜祥和的,卻被一連串不祥的預兆打破。從幾天前開始,大地就隱隱作祟,到了7點左右,地鳴聲愈發劇烈。早上7點45分,一陣劇烈的搖晃襲來,還沒等眾人回過神,便聽到一聲震耳欲聾的轟鳴,只見磐梯山的方向升起了一根巨大的柱狀物! 這根由岩石、土壤和水蒸氣組成的巨柱,扶搖直上,直衝雲霄,那景象,簡直就像是電影裡的末日場景!據說當時的景象如同「日食」發生一般,天地瞬間陷入一片黑暗。緊接著,夾雜著火山灰和被岩漿加熱的水蒸氣的「熱雨」傾盆而下,這場「熱雨」引發了大規模的土石流,不僅摧毀了沿途的村莊,更將河流截斷,形成了三個新的堰塞湖。而這三個湖泊,就是如今大名鼎鼎的檜原湖、小野川湖和秋元湖。 白板上那張手繪的「會津磐梯山爆發」示意圖,生動地還原了當年的場景。磐梯山被炸掉了一大塊,山腳下的村莊被夷為平地,原本流淌的河流被截斷,形成了三個巨大的湖泊。這幅景象,讓人不禁感嘆大自然的威力,也對當年受災的民眾感到深深的同情。 然而,這場災難卻也孕育出了新的生命——溫泉。白板上寫著:「中之澤溫泉,從江戶時代開始就是湯治場」。據說,這裡的源泉來自安達太良山的火山口,直線距離約7公里。沼之平地區在過去還是人們採集硫磺的地方,這裡出產的硫磺純度高達99%,品質極佳。 這裡的溫泉,屬於酸性泉,自古以來就以其強大的療效而聞名。泉水源自地下水與天水、加上活躍的火山活動交互影響的...

Connect LinkedIn Account into your Rails Application with Authlogic and OAuth

LinkedIn launched its new API in November 2009, allowing any developer brave enough to implement OAuth to integrate with one of the largest social networks around. Seeking an opportunity to really understand OAuth more fully and play around with the LinkedIn API at the same time, I created the LinkedIn connect sample code.

This is a sample Ruby on Rails tutorial to demonstrate how you can use the LinkedIn API to authenticate users and pull their profile data into your own website.


GETTING STARTED


Before you can use the LinkedIn API, you'll need to set up your API keys.

Getting Started with the LinkedIn API


1. Where do I begin? Start by navigating to http://developer.linkedin.com. This is Linkedin developer portal where you can read API documentation, collaborate with other developers, and keep abreast of changes to the LinkedIn API. From here, click on “LinkedIn APIs.”

2. Now click on “Request an API Key”

3. After logging in, you’re now presented with an opportunity. You can create as many API keys as you like, one for each application that you create. Let’s get started.


4. This isn’t as complicated as it looks. Let’s look closely.
Application Developers: This is a list of your LinkedIn Connections that will receive network updates published by your application and is used only while it is in development mode. You need to be connected to any LinkedIn member that you want to put on this whitelist. Interface Language: Your application is provided in one or more languages to end users. Let us know what those languages are so we can better support you in the future. Programming Tools: Knowing what kind of programming languages and tools you use to develop your application lets us know what languages and environments are most important for us to support. Just a few more fields to go over!

5. Ready to get your API keys? When you’re done, click “Add Application”
Contact Info: Tell us how to get in contact with you should we have a question about or there is a problem with your application.
OAuth Redirect URL: If you have a static location that should always be used for your OAuth callbacks, you can specify it here. It is recommended that you use the oauth_callback parameter in the appropriate requests instead.
Agreement Language: If you’d like to force the login screen to appear in one of the languages LinkedIn supports, you can set that here. It is recommended to leave the setting at “Browser Locale Setting.”
Terms of Service/CAPTCHA: Please do read our API Terms of Use. You cannot create an API key without agreeing to our terms. You’ve likely seen a CAPTCHA before, and it needs little explanation.



6. You’ve got your API keys. What’s next?
The LinkedIn Developer Network is where you’ll find guidelines, documentation, and growing community of developers.


RUBY GEM INSTALLATION


First you need to upgrade your Rails VERSION to 2.3.x, and install the required Ruby Gems below:

1. Setup and use Authlogic

$ sudo gem install authlogic

2. Install OAuth and Authlogic_Oauth

$ sudo gem install oauth
$ sudo gem install authlogic-oauth

3. Install other required Ruby gems

$ sudo gem install json
$ sudo gem install crack

Or for older version of Rails, you can install it as a plugin:

$ script/plugin install git://github.com/binarylogic/authlogic.git
$ script/plugin install git://github.com/jrallison/authlogic_oauth.git

* Authlogic at Github:http://github.com/binarylogic/authlogic
* Authlogic Example: http://github.com/binarylogic/authlogic_example


SETUP API KEY IN YOUR APP


Create load_linkedin_config.rb in #{RAILS_ROOT}/config/initializers directory

Create linkedin_config.yml in #{RAILS_ROOT}/config directory



DATABASE MIGRATION


1. Make some changes to user table in your database:

$ script/generate migration AddLinkedinConnectToUsers

2. Create Position,Education and Connection model:

$ script/generate model position

$ script/generate model education

$ script/generate model connection


3. Modify the User model, add the content below to the #{RAILS_ROOT}/app/models/user.rb:

The private method "populate_oauth_user", which is called before user record created, and is used to fetch profile info (name, headline, industry, profile pic, public url, summary, specialties, web urls) in LinkedIn.com, and save these info to your user record. The other private method "populate_child_models", which is called after user record created, and which will save past position info (companies, job titles, durations, descriptions), education info (schools, degrees, field of study, dates, etc) and connections info (names, industries, headlines, profile pics) for user.

4. Modify the Connection model, add the contents below to the #{RAILS_ROOT}/app/models/connection.rb:

5. Modify the Education model, add the content below to the #{RAILS_ROOT}/app/models/education.rb:

6. Modify the Position model, add the content below to the #{RAILS_ROOT}/app/models/position.rb:

7. Create UserSession model, and define the oauth_consumer class method on your UserSession model:


CONTROLLER METHOD


You only need to save your objects this way if you want the user to authenticate with their OAuth provider.

That being said, you probably want to do this in your controllers. You should do this for BOTH your User objects and UserSession objects (assuming you are authenticating users). It should look something like this:

You should save your @user objects this way as well, because you also want the user to authenticate with OAuth.

In my case, I have to integrating the LinkedIn OAuth Sign in feature to my current Rails project, so I changed the "Create" method in my UsersController like this way:

When the user click on the LinkedIn Login button and we can't find the oauth_token and oauth_secret in the database, the user will be redirect to signup page with "linkedin_user" parameter. After fill in the fields, they will be redirect to LinkedIn authentication page, then user record will be created. If we can find the oauth_token and oauth_secret in the database, the user will be login to the site.



ADD REGISTER BUTTON


You can simply use the "oauth_register_button" helper method to add LinkedIn register buttons to your views, like this:

Now add some style in your CSS file for LinkedIn button:



NEXT STEPS


Now we have user's LinkedIn data saved in the database, so you can write some codes to show the user's LinkedIn profile data (such as Username, Headline, Location, Education, Position, Websites, Skills, Experience, Connections) in the website.

You may want to add methods to update profile info on each login or update request. Or pull status updates, specialties, and current position for connection.

If you're interested in learning more about LinkedIn and OAuth, I encourage you to checkout Taylor Singletary's presentation LinkedIn OAuth: Zero to Hero.

熱門文章

Jan 2025【日本東北】溫泉三昧之旅① 在大雪飄落的雪國,追尋秘湯之宿與極上美食(秋田~探訪有日本溫泉界頂點之稱的秘湯乳頭溫泉鶴之湯)

Feb, 2024【台中西區】桃太郎日本料理|隱身巷弄裡的39年老字號無菜單料理|食材新鮮、自然美味

2019.10.9~13【令和元年の紅葉の山旅へ PART①】秋の贅沢、黒部川の源流へ北アルプス深部を縦走5日間!Day0、Day1(前泊、折立~藥師岳山莊)

台中【馨苑小料理】西區店|巷弄裡的人氣台菜店|米其林必比登推薦美食|提供合菜、個人套餐

【秋季清邁遊 Part 5|Visit Mae Ya Waterfall and Wachirathan Waterfall】The 6 Day Itinerary To Explore Chiang Mai And Northern Thailand's Mountains

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

Jan 2025【日本東北】溫泉三昧之旅② 在大雪飄落的雪國,追尋秘湯之宿與極上美食(仙台~品嚐極上米澤牛&奧羽的百年藥湯-鎌先溫泉)

April, 2023【彰化芬園】步道平坦好走!彰化八卦山「挑水古道」+十八觀音步道、碧山古道O形環走

Mar 2025【新竹五峰】油羅山森呼吸:擁抱原始柳杉林秘境之美(羅山林道第一登山口往返)

Dec 9, 2023【新北烏來】西羅岸環線~烏來三山健行(保慶宮起登,連走拔刀爾山〜高腰山〜美鹿山)

文章列表

Contact

名稱

以電子郵件傳送 *

訊息 *