Spring-trees
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- title: line liff 規範紀錄 tags: Line, liff --- # line liff 規範紀錄 ## liff 設定頁: - `Bot link feature`: **可透過此設定,在驗證時跳出是否加入官方帳號的好友。** > On (Normal):小提醒 > On (Aggressive):單獨一頁提醒 > Off:不開啟 > #### 注意: 就算不加入好友,也可開啟 liff 網頁繼續執行。 - `Module mode`: **是否開啟分享功能按鈕(在上方關閉鈕旁)** > on: 不開啟 > off: 開啟 - `Method for converting additional information in the LIFF URL:` **選擇LIFF URL的工作方式·** > concatenate: 新方式 > replace: 舊方式 ### 新LIFF URL - 使用 LIFF SDK v2.3.0 或 更高版本 ## 2 試用所有不可自定義的 `LIFF URL`。 ### 2.1 在 LINE app 中打開通用連結的 LIFF URL 在這種情況下,“Destination URL” 將是 “endpoint URL” 加上 “路徑” 和 “Query param” ,然後加上 LIFF 的 URL fragment 的形式顯示。 ![](https://i.imgur.com/tnpvTr6.png) > 新模式(concatenate) Destinatioin URL = Endpoint URL + LIFF URL fragment > 傳統模式(replace) Destinatioin URL = Endpoint URL + LIFF URL fragment ### 2.2 在外部瀏覽器中打開 `LIFF URL` 在這種情況下,“Destination URL” 將是 “endpoint URL” 加上 “路徑” 和 “Query param” ,**但是新的 LIFF URL 和舊版本之間會有區別。** ![](https://i.imgur.com/44C1Gut.png) > 新模式(concatenate):Destinatioin URL = Endpoint URL > 傳統模式(replace):Destinatioin URL = Endpoint URL + &liff.state= ### 2.3 在 LINE 中打開 `LIFF URL(如 LINE Scheme)` 在這種情況下,機制與 2.1 完全相同。 **註記:LIFF URL 的 LINE scheme 模式僅適用於 Android、iOS 和 iPad 上的 LINE app。** ![](https://i.imgur.com/BLoUoi8.png) > 新模式(concatenate) Destinatioin URL = Endpoint URL + LIFF URL fragment > 傳統模式(replace) Destinatioin URL = Endpoint URL + LIFF URL fragment ### 總結 當LIFF URL為固定且沒有帶任何的Path、Query Parameter時: * **新模式(concatenate)** 與 **傳統模式(replace)** 沒有任何差異 * 在外部瀏覽器中打開 LIFF URL的情形下, 新模式(concatenate)的 Destinatioin URL = Endpoint URL。 傳統模式(replace)的 Destinatioin URL = Endpoint URL + **&liff.state=** ## 3 使用帶有 Path、Query Parameter 和 URL fragment 的 LIFF URL 測試。 ### 3.1 在 LINE app 中打開通用連結的 LIFF URL 如果在通用連結上附加了 Path、 Query Parameter 或 URL fragment,將有兩種重新導向的步驟: 1. 首先先重新導向到到 Endpoint URL,接著通用連結後的 Path、Query Parameter 到 URL fragment 進行 URL 編碼,然後將編碼後的值設定在 liff.state 上,其形式包含原本 LIFF 的設定值。 2. 將重新導向到 Destination URL,而 liff.state 的值將會解碼並將該值附加到Endpoint URL 上。 ![](https://i.imgur.com/rHVDStp.png) > 新模式(concatenate) Destination URL = Endpoint URL + 通用連結的Path 及 Query parameter。 > 傳統模式(replace) Destination URL = Endpoint URL - Endpoint URL 中的所有 path 和 Query parameter + 通用連結的Path 及 Query parameter。此範例中,若您想帶 /liff2,則必須將通用連結指定為 https://liff.line.me/1653575653-8WwXMavK/liff2/path?param=9#hashtag ### 3.2 在外部瀏覽器中打開通用連結 該機制與 在 2.1 中的工作方式完全相同,**不同之處在於在第一次導向時的結尾沒有附加 LIFF 原本 URL fragment 的值。** ![](https://i.imgur.com/mNZqusp.png) > 新模式(concatenate) Destinatioin URL = Endpoint URL + 通用連結的Path 及 Query parameter。 > 傳統模式(replace) Destinatioin URL = Endpoint URL - Endpoint URL 中的所有 path 和 Query parameter + 通用連結的Path 及 Query parameter。 ### 3.3 在 LINE 應用中打開 LINE Scheme 如果在 LINE Scheme LIFF URL 上加了 Path、Query parameter 或 URL fragment,**在新舊模式中 Redirect 機制啟動將只有啟動一次**。接下來的傳遞過程中會將 Path、URL fragment 移除,並只能傳遞 Query param 到 endpoint URL 上。 ![](https://i.imgur.com/286PblD.png) > 新模式(concatenate) Destinatioin URL = Endpoint URL + 通用連結的Query parameter。 > 傳統模式(replace) Destinatioin URL = Endpoint URL + 通用連結的Query parameter。 ### 總結 當LIFF URL帶有Path、Query Parameter時: * #### 新模式(concatenate) Destination URL = Endpoint URL + LIFF URL的Path 及 Query parameter。 * #### 傳統模式(replace) Destination URL = Endpoint URL - Endpoint URL 中的所有 path 和 Query parameter + LIFF URL的Path 及 Query parameter。(Endpoint URL的path 和 Query parameter刪掉) * 在LINE 應用中打開 LINE Scheme的情形下,新舊模式的Destinatioin URL = Endpoint URL + LIFF URL的Query parameter + LIFF URL fragment。(只留下LIFF URL的Query parameter) ## 4 將 Path、Query parameter 和 URL fragment 加到 LINE Scheme 的方法 ### 4.1 處理附加到 Endpoint URL 的 Query param ### 4.2 liff.state 狀態 在使用了 3 部分的方法中,每當有 2 個重新導向的地方時,都會有一個名為 liff.state 的變數,該變數是處理附加到 Endpoint URL 上的 Query param,其值是 encode 來自 URL path、Query parameter 以及 URL fragment,藉由這個方法可以將我們帶到 Destination URL,讓我們看一個範例: ![](https://i.imgur.com/XrOQd8u.png) ``` 1. 從現在開始,URL fragment 禁止指定 Endpoint URL。 2. 在如下所示的 LIFF URL https://line.me/R/app/xxx-xxx 具有與 LINE Scheme line://app/xxx-xxx 有著相同的功能。 ``` 參考文件: https://engineering.linecorp.com/zh-hant/blog/new-liff-url-infomation/ https://nijialin.com/2020/07/21/LIFF-concat-replace-mode-scenario/ --- # LIFF v2 API reference **LIFF v2版本可以在LIFF browser以外的瀏覽器使用** ## liff.init() ```javascript= const liffId = 'my-liff-id' liff.init({ liffId }) ``` - 註: 起手式,一定要先執行此function才能使用其它功能 ### 應用 ```javascript= // Using a Promise object liff .init({ liffId: "123456-abcedfg" // Use own liffId }) .then(() => { // Start to use liff's api }) .catch((err) => { // Error happens during initialization console.log(err.code, err.message); }); // Using a callback liff.init({ liffId: "123456-abcedfg" }, successCallback, errorCallback); ``` ## liff.isInClient() ```javascript= liff.isInClient() ``` - 可用來判斷是不是用LIFF browser開啟。 - true: Running in LIFF browser - false: 其它瀏覽器 ### 應用 ```javascript= if (liff.isInClient()) { ...... } ``` ## liff.isLoggedIn() ```javascript= liff.isLoggedIn() ``` - check使用者是否有登入line ### 應用 ```javascript= if (liff.isLoggedIn()) { ...... } ``` - 註: 使用者需先登入line,才能拿到使用者的個人資料 ## liff.login() ```javascript= liff.login(loginConfig) ``` - 使用者在LIFF browser以外的瀏覽器時可使用 - 註: 使用者開啟LIFF browser,line應為登入的狀態,所以無法在LIFF browser裡使用liff.login() ### 應用 ```javascript= if (!liff.isLoggedIn()) { liff.login({ redirectUri: "https://example.com/path" }); } ``` ## liff.logout() ```javascript= liff.logout() ``` - 登出line帳號 - 註: 基本上在LIFF browser以外的瀏覽器使用,在LIFF browser裡使用時,會因為自動登入所以失效 ### 應用 ```javascript= if (liff.isLoggedIn()) { liff.logout(); } ``` ## liff.getProfile() ```javascript= liff.getProfile() ``` - 基本上這一步會在確認是否isLoggedIn後再使用 ### 應用 ```javascript= liff.getProfile() .then(profile => { const name = profile.displayName }) .catch((err) => { console.log('error', err); }); ``` ## liff.getFriendship() ```javascript= liff.getFriendship() ``` - 用來檢查使用者是否沒加好友,或是封鎖。 ### 應用 ```javascript= liff.getFriendship().then(data => { if (data.friendFlag) { // something you want to do } ) ``` - 註: line的版本過低,有可能會讓liff v2以上版本出錯,像是吃不到css,這時更新line的版本即可。 參考文件: https://developers.line.biz/en/reference/liff/#initialize-liff-app ## liff.shareTargetPicker() ```javascript= liff.shareTargetPicker() ``` - 分享訊息API,可以偵測是否成功分享 ```javascript= liff.shareTargetPicker([ { type: "text", text: "this is a test" } ]) .then( alert("ShareTargetPicker was launched") ).catch(function(res) { alert("Failed to launch ShareTargetPicker") }) ``` - 在 line developers後台記得勾選`shareTargetPicker` ![](https://i.imgur.com/pQO3LQb.png) 參考文件: - https://engineering.linecorp.com/zh-hant/blog/liff-share-target-picker/ - https://developers.line.biz/en/reference/liff/#share-target-picker # Liff 問題紀錄 - 在某些android手機,liff會判斷測試工具`connector.js`為不安全,無法開啟網站

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully