EN ZH

📱 LINE LIFF API

Use when building, debugging, or interacting with the LINE Front-end Framework (LIFF) SDK (initialization, authentication, retrieving user profiles, sending messages, and sharing target pickers).

Overview

This skill provides a structured reference for integrating and interacting with the LINE Front-end Framework (LIFF) client-side JS SDK. It covers LIFF SDK properties, initialization, authentication, user context, profile retrieval, and custom features like share target picker and scanning codes.

When to Use

Core Pattern

Always call liff.init() as early as possible and wait for the returned promise to resolve before calling other LIFF SDK methods.

Initialization & Login Flow (JavaScript)

import liff from '@line/liff';

async function initializeLiff(liffId) {
  try {
    await liff.init({ liffId });
    if (!liff.isLoggedIn()) {
      // Automatically redirect to LINE Login if not logged in
      liff.login();
    } else {
      // Proceed to fetch profile or use other SDK features
      const profile = await liff.getProfile();
      console.log('User Profile:', profile);
    }
  } catch (error) {
    console.error('LIFF initialization failed:', error.code, error.message);
  }
}

Quick Reference

Methods Available Before liff.init()

These methods can be used to query the environment before the SDK is fully initialized:

Core SDK Methods

Method Return Type Description
liff.init(config) Promise<void> Initializes the LIFF app with liffId
liff.isLoggedIn() Boolean Checks if the user is authenticated
liff.login(options) void Triggers LINE login flow
liff.logout() void Logs out the user
liff.getProfile() Promise<Profile> Gets user profile (name, picture, status)
liff.getDecodedIDToken() Object Decodes the user's ID OIDC token (contains email)
liff.sendMessages(msgs) Promise<void> Sends messages to current chat (max 5)
liff.shareTargetPicker(msgs) Promise<Response> Opens a friend picker to share messages
liff.openWindow(options) void Opens a URL in the LIFF browser or external browser

Implementation Steps

  1. Register LIFF App: Create a LINE Login channel in the LINE Developers Console and register your LIFF app to get a LIFF ID and configure the Endpoint URL.
  2. Import SDK: Add LIFF SDK to your project via CDN (https://static.line-scdn.net/liff/edge/2/sdk.js) or npm (npm install @line/liff).
  3. Initialize: Call liff.init({ liffId }). Make sure to trigger URL changes or analytics pageviews only after the init promise resolves to prevent credential leakage.
  4. Acquire Scopes: Ensure your channel is granted the necessary scopes (e.g. profile, openid, chat_message.write) in order to call profile or messaging APIs.
  5. Verify Tokens (Server Side): If you need to verify the user identity on your backend, send the raw ID token (retrieved via liff.getIDToken()) or Access Token to your backend and call LINE's verification endpoints.

Common Mistakes

← Back to Skills