Jan 2025【日本東北】溫泉三昧之旅⑤ 在大雪飄落的雪國,追尋秘湯之宿與極上美食(福島~被時光遺忘下的江戶原風景,日本三大茅葺聚落大內宿)

圖片
清晨的陽光穿過窗櫺,灑落在榻榻米上,為房間增添了一抹溫暖的光輝。窗外,白雪皚皚的山脈在晴朗的天空下閃閃發光,預示著美好的一天。我起身走到窗邊,深深吸了一口清新的冬日空氣,心中充滿了對即將到來的一天以及仙峽閣旅館美味早餐的期待。 旅館的餐廳瀰漫著舒適的氛圍。我坐在窗邊的座位上,渴望一邊欣賞迷人的雪景,一邊享用我的早餐。一個擺盤精美的早餐托盤送到了面前,上面擺滿了各種誘人的菜餚。 我的目光首先被一碗晶瑩剔透的白米飯吸引,它的香氣瀰漫在空氣中。旁邊是一份色彩繽紛的沙拉,新鮮的蔬菜搭配玉米粒,令人食慾大增。烤鮭魚散發著陣陣香味,魚皮烤得酥脆可口。溫泉蛋浸泡在清淡的高湯中,看起來既美味又暖胃。 其他幾道小菜也讓這份早餐更加豐富:燉菠菜、裙帶菜炒蒟蒻、山藥泥佐醬油,以及醃梅子和醃黃瓜。最後,一小杯香甜的芒果優格為這頓早餐畫上了完美的句點。 這份早餐不僅美味,而且營養均衡,為我在這個冬季仙境中探索一天提供了滿滿的能量。我細細品味著每一道菜餚,感受著旅館的用心和款待,心中充滿了感激之情,感謝這美好的一天有如此美好的開始。 飯後早晨,我踏出旅館的暖簾,迎接我的是一片銀白色的世界。蘆之牧溫泉街靜靜地沉睡在會津深山的懷抱中,厚厚的積雪覆蓋著屋頂、街道和樹木,彷彿時間也凍結在這一刻。 呼出的氣息在冰冷的空氣中凝結成白霧,我沿著溫泉街漫步,腳步聲在寂靜的早晨顯得格外清晰。偶爾,可以聽見屋簷上融雪滴落的聲音,或是遠處傳來的幾聲鳥鳴,更增添了這份寧靜的氛圍。 阿賀川靜靜地流淌在山谷間,河面上覆蓋著薄薄的冰層,在陽光的照射下閃閃發光。河岸邊的樹木披上了雪白的冬衣,枝椏交錯,形成一道道優美的弧線。溫泉旅館的屋頂冒著裊裊炊煙,為這寒冷的冬日增添了一絲溫暖。 漫步在空無一人的溫泉街上,我彷彿置身於一個與世隔絕的世外桃源。這份寂靜,這份純淨,洗滌了我的心靈,讓我感受到久違的平靜與祥和。 凛冬將群山染成了素雅的銀白,積雪在山坡上鋪陳開來,厚薄錯落,像是誰不經意間揮灑的筆墨,濃淡相宜。裸露的枝枒,在寒風中輕輕搖曳,仿佛在低聲訴說著冬日的故事。遠處的山巒,在霧氣的籠罩下,若隱若現,宛如仙境一般,讓人心生嚮往。 蘆之牧溫泉的冬日,沒有喧囂,沒有繁華,只有那份獨特的靜謐與安詳,像一首悠揚的樂曲,在山谷間輕輕回蕩,令人陶醉其中,忘卻了塵世的煩惱。 這山,這雪,這寧靜的溫泉小鎮,這氤氳的霧氣,交織成一幅絕美的冬日畫卷,...

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.

熱門文章

July 2024【台北士林】陽明山彼端的原始秘境|颱風後的鹿角坑生態保護區|循著疊石指引造訪楓林瀑布

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

Jan 2025【苗栗三義】富貴牡丹(三義館)人文藝術餐廳|預約制|在美術館裡吃無菜單料理

Jan 2025【日本東北】溫泉三昧之旅⑤ 在大雪飄落的雪國,追尋秘湯之宿與極上美食(福島~被時光遺忘下的江戶原風景,日本三大茅葺聚落大內宿)

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

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

May 2023【雲林古坑】 負離子濃度達都市40倍/漫步木馬古道/順訪雲嶺之丘/山合苑喝咖啡/秋田犬

日本の登山の歷史

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

Mar 2025【桃園楊梅】福人登山步道輕鬆行:探索綠意盎然的自然步道

文章列表

Contact

名稱

以電子郵件傳送 *

訊息 *