目前在台灣,最多人使用的通訊軟體是Line,據說有將近2000萬用戶?!Facebook登入、Google登入已成為慣例,Apple登入在2020年之後開始強迫開發者整合。其實Line登入也緊跟隨在後,許多平台也已整合之,未來可多加善用。
我嘗試整合Line Login,發現相當簡單,可以先下載官方範例專案:Line登入範例專案。
首先要在Line開發者平台申請帳號,接著建立Providers,將基本資料填入更新。
下載並開啟Line登入範例專案,將info.plist的Channel ID改成自己申請的,Line後台設定iOS bundle ID要跟當前專案一致。
就這樣編譯到手機或模擬器,點擊登入按鈕,若已有安裝Line,即可跳轉至Line,會呈現授權畫面;若沒安裝Line,則會跳出網頁的登入畫面,必須填入帳密。
可見頭像和下面三行字,是由Line開發者後台設定:
- Channel icon
- Channel name
- Provider
- Channel description
用戶被請求授權的有兩項,程式碼中設定Permissions:profile、openid。
用戶授權後,可拿到資料:
Printing description of profileData:
{
accesstoken = “ey…";
displayname = “嘿嘿嘿";
pictureurl = “https://profile.line-scdn.net/…";
statusmessage = “\U74b0\U5cf6\U5b8c\U5f8c\U8981\U74b0\U904a\U4e16\U754c\Uff5e";
userid = XXX;
}
Printing description of openIDData:
{
audience = 123;
expiration = “18-06-2020 12:53″;
issueAt = “18-06-2020 11:53″;
issuer = “https://access.line.me";
name = “嘿嘿嘿";
pictureUrl = “https://profile.line-scdn.net/…";
subject = 321;
}
如此就可以如同Facebook登入、Google登入,將所需的資料傳送至我們的資料庫建立或管理用戶帳號。
還有其他功能可嘗試:
- Log out the user
- Get the user profile
- Verify the access token
- Refresh the access token
- Get the friendship status between a LINE Official Account linked to the channel and user
- View ID token information
參考:Line開發者平台、Line登入範例專案。
隨意留個言吧:)~