Skip to content

LINE

LINE 是 LY Corporation 的即时通讯应用。Protocol Launcher 可以生成用于打开 LINE 应用界面、LIFF 应用和 LINE MINI App 的官方 LINE URL scheme 链接。

用法

有两种方式使用此库:

  • On-Demand 从子路径导入,有利于 tree-shaking 并保持包体积较小。
  • Full Import 从根包导入,写起来更方便,但会包含所有应用模块。

生产构建建议使用 On-Demand;快速脚本或演示可以使用 Full Import。

选择安装方式

按需加载
推荐使用。生产环境优化。
全量导入
使用便捷。适合快速脚本。

LINE 当前官方 URL scheme 文档支持以 https://line.me/R/https://liff.line.me/https://miniapp.line.me/ 开头的 URL。它支持 LINE for iOS 和 LINE for Android,不支持 LINE for PC(macOS、Windows)。已废弃的 line:// 和 LIFF v1 URL 形式不会暴露为 helper。

相机与位置

打开相机、相册或位置界面。LINE 官方文档将相机和相册链接限定为只能从 LINE 聊天中使用,位置链接限定为用户与 LINE Official Account 的一对一聊天。

On-Demand
ts
import { openCamera, openCameraRollSingle, openCameraRollMulti, openLocation } from 'protocol-launcher/line'

const cameraUrl = openCamera()
const singleImageUrl = openCameraRollSingle()
const multiImageUrl = openCameraRollMulti()
const locationUrl = openLocation()

Official Account

打开或分享 LINE Official Account 的资料页、LINE VOOM、业务资料页、LINE VOOM 帖子或聊天界面。路径中的 Official Account ID 会按官方要求 percent-encode;LINE VOOM 和业务资料页 URL 使用不带 at-sign(@)前缀的 ID。LINE 官方说明,percent-encoded 的 recommendOA 形式在早于 13.8.0 的 LINE for Android 版本上不可用。

On-Demand
ts
import { openOfficialAccountProfile, recommendOfficialAccount, openOfficialAccountVoom, openOfficialAccountBusinessProfile, openOfficialAccountVoomPost, openOfficialAccountChat } from 'protocol-launcher/line'

const profileUrl = openOfficialAccountProfile({
  lineId: '@linedevelopers',
})

const recommendUrl = recommendOfficialAccount({
  lineId: '@linedevelopers',
})

const voomUrl = openOfficialAccountVoom({
  lineId: 'linedevelopers',
})

const businessProfileUrl = openOfficialAccountBusinessProfile({
  lineId: 'linedevelopers',
})

const voomPostUrl = openOfficialAccountVoomPost({
  lineId: 'linedevelopers',
  postId: '1234567890',
})

const chatUrl = openOfficialAccountChat({
  lineId: '@linedevelopers',
  text: 'Hi there!',
})

分享与个人资料

打开带文本的「Share with」界面、用户的「My profile」界面,或用户的「LINE ID」界面。

On-Demand
ts
import { shareText, openMyProfile, openProfileSetId } from 'protocol-launcher/line'

const shareUrl = shareText({
  text: 'Hi there!',
})

const myProfileUrl = openMyProfile()
const lineIdUrl = openProfileSetId()

常用界面

打开 LINE 的 Chats、Shopping、Wallet、Add friends、LINE Official Accounts 和 LINE VOOM Following 界面。

On-Demand
ts
import { openChats, openShopping, openWallet, openAddFriends, openOfficialAccounts, openVoomFollowing } from 'protocol-launcher/line'

const chatsUrl = openChats()
const shoppingUrl = openShopping()
const walletUrl = openWallet()
const addFriendsUrl = openAddFriends()
const officialAccountsUrl = openOfficialAccounts()
const voomFollowingUrl = openVoomFollowing()

设置

打开 LINE 的各类设置界面。LINE 官方文档分别列出了 iOS 与 Android 的主题设置 URL,因此 helper 也拆成两个平台函数。

On-Demand
ts
import { openSettings, openAccountSettings, openAuthorizedApps, openConnectedDevices, openPrivacySettings, openStickerSettings, openMyStickers, openThemeSettingsIos, openThemeSettingsAndroid, openMyThemes, openNotificationAuthorizedApps, openChatSettings, openDisplaySuggestions, openCallSettings, openFriendsSettings, openVoomSettings } from 'protocol-launcher/line'

const settingsUrl = openSettings()
const accountUrl = openAccountSettings()
const authorizedAppsUrl = openAuthorizedApps()
const connectedDevicesUrl = openConnectedDevices()
const privacyUrl = openPrivacySettings()
const stickerSettingsUrl = openStickerSettings()
const myStickersUrl = openMyStickers()
const themeSettingsIosUrl = openThemeSettingsIos()
const themeSettingsAndroidUrl = openThemeSettingsAndroid()
const myThemesUrl = openMyThemes()
const notificationsUrl = openNotificationAuthorizedApps()
const chatSettingsUrl = openChatSettings()
const suggestionsUrl = openDisplaySuggestions()
const callSettingsUrl = openCallSettings()
const friendsSettingsUrl = openFriendsSettings()
const voomSettingsUrl = openVoomSettings()

Sticker 与 Theme 商店

打开 Sticker Shop 页面、贴图排行榜标签、贴图作者页,以及 Theme Shop 商品页。

On-Demand
ts
import { openSticker, openStickerCategoryRanking, openStickerAuthor, openStickerShop, openStickerShopRank, openStickerShopNew, openStickerShopFree, openStickerShopCategories, openTheme } from 'protocol-launcher/line'

const stickerUrl = openSticker({
  packageId: 11537,
})

const categoryRankingUrl = openStickerCategoryRanking({
  categoryId: 21,
})

const authorUrl = openStickerAuthor({
  authorId: 12345,
})

const stickerShopUrl = openStickerShop()
const rankUrl = openStickerShopRank()
const newUrl = openStickerShopNew()
const freeUrl = openStickerShopFree()
const categoriesUrl = openStickerShopCategories()

const themeUrl = openTheme({
  productId: '0bac8fed-4c75-40c5-9982-e9ecc3b9d191',
})

LIFF 与 MINI App

打开 LIFF 应用或生成 LINE MINI App permanent link。两个 helper 都支持 LINE 官方文档中的附加 path、query 和 hash 信息。

On-Demand
ts
import { openLiff, openMiniApp } from 'protocol-launcher/line'

const liffUrl = openLiff({
  liffId: '1234567890-AbcdEfgh',
  path: '/path_A/path_B/',
  query: {
    key1: 'value1',
    key2: 'value2',
  },
  hash: 'URL-fragment',
})

const miniAppUrl = openMiniApp({
  liffId: '123456-abcedfg',
  path: '/shop',
  query: {
    search: 'shoes',
  },
  hash: 'item10',
})

外部浏览器

添加 LINE 官方 query 参数,让目标 URL 在外部浏览器中打开,或在 Android 上用 Chrome custom tab 打开。LINE 官方文档说明这些参数不支持 LIFF 应用,因此 helper 会拒绝 https://liff.line.me/... 等 LIFF app URL 和 https://miniapp.line.me/... 等 LINE MINI App URL。

On-Demand
ts
import { openExternalBrowser, openAndroidChromeCustomTab } from 'protocol-launcher/line'

const externalBrowserUrl = openExternalBrowser({
  url: 'https://example.com/',
})

const chromeCustomTabUrl = openAndroidChromeCustomTab({
  url: 'https://example.com/path?foo=bar#section',
})

官方文档