このページの更新は終了しました。最新のドキュメントは、https://developers.line.me でご覧いただけます。 Close
Navbar
shell java ruby go php perl python node.js

Messaging API

LINE Platformが提供する Messaging API により、LINEのトーク画面を使った対話型Botアプリケーションの開発が可能になります。

Messaging APIを構成するコンポーネントは以下です。

Webhooks

友だち追加情報やユーザから送信されたメッセージをリアルタイムに受信する仕組みです。

Reply Message

ユーザから受信したメッセージやイベントに対して返信するAPIです。

Push Message

任意のタイミングでユーザにメッセージを送信するAPIです。

Multicast

複数のユーザに任意のタイミングでメッセージを送信するAPIです。

Content

ユーザから受信した画像や動画、音声をダウンロードするAPIです。

Profile

ユーザのプロフィール情報を取得するAPIです。

Leave

参加したグループやトークルームから退出するAPIです。

LINE Bot SDK

Messaging APIを使ったBotアプリケーションの開発を容易にする各言語向けのSDKを用意しています。
本ドキュメントでは、これらのSDKを使ったサンプルコードも併せて掲載しています。

Stay connected

Twitterの公式アカウントでは、開発者向け情報、APIの更新情報、不具合に関する情報などを提供しています。
また、本ドキュメントやAPIの不具合に関するご連絡も受け付けています。

LINEの公式アカウント"LINE Developers"でも最新の情報を配信いたします。

Getting started

Messaging API の利用開始にはまずこちらの資料を確認ください。

Common specifications

Messaging APIの各APIに共通の仕様を記載します。

Rate limits

APIごとに呼び出し回数の制限があります。
制限はプランによって異なります。

Plan Limit
Developer Trial 1,000/分
その他 10,000/分

Status codes

Messaging APIが返す主要なstatus codeは以下です。

Error code Description
200 OK リクエスト成功
400 Bad Request リクエストに問題があります。リクエストパラメータやJSONのフォーマットを確認してください。
401 Unauthorized Authorizationヘッダを正しく送信していることを確認してください。
403 Forbidden APIの利用権限がありません。ご契約中のプランやアカウントに付与された権限を確認してください。
429 Too Many Requests アクセス頻度を制限内に抑えてください。
500 Internal Server Error APIサーバ側の一時的なエラーです。

Response headers

Messaging APIはレスポンスに以下のHTTPヘッダを含めます。

Response header Description
X-Line-Request-Id リクエスト毎に発行される識別子

Error response

Error response JSONの例

{
  "message":"The request body has 2 error(s)",
  "details":[
    {"message":"May not be empty","property":"messages[0].text"},
    {"message":"Must be one of the following values: [text, image, video, audio, location, sticker, template, imagemap]","property":"messages[1].type"}
  ]
}


{
  "message":"Invalid reply token"
}

エラー時のresponse bodyは、以下のフィールドを持つJSONデータです。

Field Type Description
message String エラーの概要
details[].message String 詳細なエラー内容
details[].property String エラーの発生箇所

または

Field Type Description
message String エラー内容

Error messages

Error response JSONにおける message フィールドに設定される主要なエラーメッセージは以下です。

Message Description
The request body has X error(s) リクエストボディに設定されたJSONに問題がある場合に発生します。詳細はdetails[].messageおよびdetails[].propertyに表示されます。
Invalid reply token reply messageにおいて、無効なreplyTokenが使用された場合に発生します。
The property, ‘XXX’, in the request body is invalid (line: XXX, column: XXX) リクエストボディに設定されたJSONに無効な値が含まれている場合に発生します。XXXの部分には具体的な箇所が表示されます。
The request body could not be parsed as JSON (line: XXX, column: XXX) リクエストボディがJSONとして処理できない場合に発生します。XXXの部分には具体的な箇所が表示されます。
The content type, 'XXX’, is not supported APIの定義と異なるcontent typeでリクエストされた場合に発生します。
Authentication failed due to the following reason: XXX API呼び出し時の認証に失敗した場合に表示されます。XXXの部分には理由が表示されます。
Access to this API is not available for your account 利用権限の無いMessaging APIを呼び出した場合に発生します。
Failed to send messages メッセージの送信ができなかった場合に発生します。push messageで存在しないuserIdを指定した場合などに発生します。

Webhooks

Webhook request bodyの例

{
  "events": [
      {
        "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA",
        "type": "message",
        "timestamp": 1462629479859,
        "source": {
             "type": "user",
             "userId": "U206d25c2ea6bd87c17655609a1c37cb8"
         },
         "message": {
             "id": "325708",
             "type": "text",
             "text": "Hello, world"
          }
      }
  ]
}

友だち追加やメッセージ送信などの イベント は、
Channel Consoleで設定されたwebhook URLに HTTPS POSTリクエスト で通知されます。Channel ConsoleはLINE Business Centerのアカウントリストページからアクセスすることができます。

Botのサーバはこのリクエストを受信し、イベントに応じた処理を行ってください。

Request headers

Request header Description
X-Line-Signature 署名検証に使用するsignature

Request body

Request bodyは、webhook event objectの配列を含むJSONオブジェクトです。

Field Type Description
events Array of webhook event object 受信したイベント情報

Response

WebhookのHTTPS POSTリクエストに対しては、常にstatus code 200を返してください。

Signature validation

リクエストの送信元がLINEであることを確認するために署名検証を行わなくてはなりません。
各リクエストには X-Line-Signature ヘッダが付与されています。
X-Line-Signature ヘッダの値と、request body と Channel secret から計算した signature が同じものであることをリクエストごとに 必ず検証してください

検証は以下の手順で行います。

  1. Channel secretを秘密鍵として、HMAC-SHA256アルゴリズムによりrequest bodyのダイジェスト値を得る。
  2. ダイジェスト値をBASE64エンコードした文字列が、request headerに付与されたsignatureと一致することを確認する。

Webhook event object

Webhook event objectの例

{
  "events": [
    {
      "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA",
      "type": "message",
      "timestamp": 1462629479859,
      "source": {
        "type": "user",
        "userId": "U206d25c2ea6bd87c17655609a1c37cb8"
      },
      "message": {
        "id": "325708",
        "type": "text",
        "text": "Hello, world"
      }
    },
    {
      "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA",
      "type": "follow",
      "timestamp": 1462629479859,
      "source": {
        "type": "user",
        "userId": "U206d25c2ea6bd87c17655609a1c37cb8"
      }
    }
  ]
}

LINE Platformで発生したイベントを表すJSONオブジェクトです。

Common fields

全ての webhook event object には以下のフィールドが含まれます。

Field Type Description
type String イベントの種類を表す識別子
timestamp Number イベントの時刻を表すミリ秒
source User
Group
Room
イベントの送信元を表すJSONオブジェクト

Source user

Source userの例

  "source": {
    "type": "user",
    "userId": "U206d25c2ea6bd87c17655609a1c37cb8"
  }

イベント送信元ユーザを表すオブジェクトです。

Field Type Description
type String user
userId String 送信元ユーザを表す識別子

Source group

Source groupの例

  "source": {
    "type": "group",
    "groupId": "Ca56f94637cc4347f90a25382909b24b9",
    "userId": "U206d25c2ea6bd87c17655609a1c37cb8"
  }

Source group の例(userIdが含まれない場合)

  "source": {
    "type": "group",
    "groupId": "Ca56f94637cc4347f90a25382909b24b9"
  }

イベント送信元グループを表すオブジェクトです。

Field Type Description
type String group
groupId String 送信元グループを表す識別子
userId String 送信元ユーザを表す識別子

Source room

Source roomの例

  "source": {
    "type": "room",
    "roomId": "Ra8dbf4673c4c812cd491258042226c99",
    "userId": "U206d25c2ea6bd87c17655609a1c37cb8"
  }

Source roomの例(userIdが含まれない場合)

  "source": {
    "type": "room",
    "roomId": "Ra8dbf4673c4c812cd491258042226c99"
  }

イベント送信元トークルームを表すオブジェクトです。

Field Type Description
type String room
roomId String 送信元トークルームを表す識別子
userId String 送信元ユーザを表す識別子

Message event

メッセージが送信されたことを示すEvent Objectです。
messageフィールドには、メッセージの種別ごとに異なるmessage objectが含まれます。
このイベントは返信可能です。

Field Type Description
type String message
replyToken String このイベントへの返信に使用するトークン
message Text
Image
Video
Audio
File
Location
Sticker
メッセージ内容

Text message

Text messageの例

{
  "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA",
  "type": "message",
  "timestamp": 1462629479859,
  "source": {
    "type": "user",
    "userId": "U206d25c2ea6bd87c17655609a1c37cb8"
  },
  "message": {
    "id": "325708",
    "type": "text",
    "text": "Hello, world"
  }
}

イベント送信元から送信されたテキストを表すmessage objectです。

Field Type Description
id String メッセージ識別子
type String text
text String メッセージのテキスト

Image message

Image messageの例

{
  "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA",
  "type": "message",
  "timestamp": 1462629479859,
  "source": {
    "type": "user",
    "userId": "U206d25c2ea6bd87c17655609a1c37cb8"
  },
  "message": {
    "id": "325708",
    "type": "image"
  }
}

イベント送信元から送信された画像を表すmessage objectです。
Contentから画像バイナリデータを取得できます。

Field Type Description
id String メッセージ識別子
type String image

Video message

Video messageの例

{
  "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA",
  "type": "message",
  "timestamp": 1462629479859,
  "source": {
    "type": "user",
    "userId": "U206d25c2ea6bd87c17655609a1c37cb8"
  },
  "message": {
    "id": "325708",
    "type": "video"
  }
}

イベント送信元から送信された動画を表すmessage objectです。
Contentから動画バイナリデータを取得できます。

Field Type Description
id String メッセージ識別子
type String video

Audio message

Audio messageの例

{
  "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA",
  "type": "message",
  "timestamp": 1462629479859,
  "source": {
    "type": "user",
    "userId": "U206d25c2ea6bd87c17655609a1c37cb8"
  },
  "message": {
    "id": "325708",
    "type": "audio"
  }
}

イベント送信元から送信された音声を表すmessage objectです。
Contentから音声バイナリデータを取得できます。

Field Type Description
id String メッセージ識別子
type String audio

File message

File messageの例

{
  "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA",
  "type": "message",
  "timestamp": 1462629479859,
  "source": {
    "type": "user",
    "userId": "U206d25c2ea6bd87c17655609a1c37cb8"
  },
  "message": {
    "id": "325708",
    "type": "file",
    "fileName": "file.txt",
    "fileSize": 2138
  }
}

イベント送信元から送信されたファイルを表すmessage objectです。
Contentからバイナリデータを取得できます。

Field Type Description
id String メッセージ識別子
type String file
fileName String ファイル名
fileSize String ファイルのバイト数

Location message

Location messageの例

{
  "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA",
  "type": "message",
  "timestamp": 1462629479859,
  "source": {
    "type": "user",
    "userId": "U206d25c2ea6bd87c17655609a1c37cb8"
  },
  "message": {
    "id": "325708",
    "type": "location",
    "title": "my location",
    "address": "〒150-0002 東京都渋谷区渋谷2丁目21−1",
    "latitude": 35.65910807942215,
    "longitude": 139.70372892916203
  }
}

イベント送信元から送信された位置情報を表すmessage objectです。

Field Type Description
id String メッセージ識別子
type String location
title String タイトル
address String 住所
latitude Decimal 緯度
longitude Decimal 経度

Sticker message

Sticker messageの例

{
  "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA",
  "type": "message",
  "timestamp": 1462629479859,
  "source": {
    "type": "user",
    "userId": "U206d25c2ea6bd87c17655609a1c37cb8"
  },
  "message": {
    "id": "325708",
    "type": "sticker",
    "packageId": "1",
    "stickerId": "1"
  }
}

イベント送信元から送信されたStickerを表すmessage objectです。
LINEの基本なstickerとその識別子の一覧は以下を参照ください。
Sticker一覧

Field Type Description
id String メッセージ識別子
type String sticker
packageId String パッケージ識別子
stickerId String Sticker識別子

Follow event

Follow eventの例

{
  "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA",
  "type": "follow",
  "timestamp": 1462629479859,
  "source": {
    "type": "user",
    "userId": "U206d25c2ea6bd87c17655609a1c37cb8"
  }
}

イベント送信元に友だち追加(またはブロック解除)されたことを示すEvent Objectです。
このイベントは返信可能です。

Field Type Description
type String follow
replyToken String このイベントへの返信に使用するトークン

Unfollow event

Unfollow eventの例

{
  "type": "unfollow",
  "timestamp": 1462629479859,
  "source": {
    "type": "user",
    "userId": "U206d25c2ea6bd87c17655609a1c37cb8"
  }
}

イベント送信元にブロックされたことを示すevent objectです。

Field Type Description
type String unfollow

Join event

Join Eventの例

{
  "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA",
  "type": "join",
  "timestamp": 1462629479859,
  "source": {
    "type": "group",
    "groupId": "cxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
  }
}

イベントの送信元グループまたはトークルームに参加したことを示すevent objectです。
このイベントは返信可能です。

Field Type Description
type String join
replyToken String このイベントへの返信に使用するトークン

Leave event

Leave eventの例

{
  "type": "leave",
  "timestamp": 1462629479859,
  "source": {
    "type": "group",
    "groupId": "cxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
  }
}

イベントの送信元グループから退出させられたことを示すevent objectです。

Field Type Description
type String leave

Postback event

Postback eventの例

{
  "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA",
  "type": "postback",
  "timestamp": 1462629479859,
  "source": {
    "type": "user",
    "userId": "U206d25c2ea6bd87c17655609a1c37cb8"
  },
  "postback": {
    "data": "action=buyItem&itemId=123123&color=red"
  }
}

イベントの送信元が、template messageに付加されたポストバックアクションを実行したことを示すevent objectです。
このイベントは返信可能です。

Field Type Description
type String postback
replyToken String このイベントへの返信に使用するトークン
postback.data String ポストバックデータ
postback.params Object Datetime picker actionでユーザが選択した日付や時刻を表すJSONオブジェクト
Datetime pickerによるポストバックの場合のみJSONに含まれます。

postback.params object

Datetime picker actionでユーザが選択した日付や時刻を表すオブジェクトです。
以下の表における full-date, time-hour および time-minute はRFC3339で定義されている形式です。

Field format Description
date full-date ユーザが選択した日付。date モードの場合のみ設定されます。
time time-hour “:” time-minute ユーザが選択した時刻。time モードの場合のみ設定されます。
datetime full-date “T” time-hour “:” time-minute ユーザが選択した日付と時刻。datetime モードの場合のみ設定されます。

Beacon event

Beacon eventの例

{
  "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA",
  "type": "beacon",
  "timestamp": 1462629479859,
  "source": {
    "type": "user",
    "userId": "U206d25c2ea6bd87c17655609a1c37cb8"
  },
  "beacon": {
    "hwid": "d41d8cd98f",
    "type": "enter"
  }
}

イベント送信元のユーザがLINE Beaconデバイスの受信圏内に出入りしたことなどを表すイベントです。
このイベントは返信可能です。

Field Type Description
type String beacon
replyToken String このイベントへの返信に使用するトークン
beacon.hwid String 発見したビーコンデバイスのハードウェアID
beacon.type String ビーコンイベントの種別
beacon.dm String (OPTIONAL) 発見したビーコンデバイスのデバイスメッセージ

「デバイスメッセージ」は、Botに通知することを目的にビーコンデバイスによって生成されたデータです。
対応するビーコンデバイスからのwebhookにのみ、beacon.dmは含まれます。
現状ではLINE Simple Beaconでご利用いただけます。
詳細はドキュメントをご確認ください。

beacon.typeはイベントの種別によって以下の文字列が含まれます。

beacon.type Description
enter ビーコンデバイスの受信圏内に入った
leave ビーコンデバイスの受信圏内から出た
banner Beacon Bannerをタップした

Reply message

Reply messageリクエストの例

curl -X POST \
-H 'Content-Type:application/json' \
-H 'Authorization: Bearer {ENTER_ACCESS_TOKEN}' \
-d '{
    "replyToken":"nHuyWiB7yP5Zw52FIkcQobQuGDXCTA",
    "messages":[
        {
            "type":"text",
            "text":"Hello, user"
        },
        {
            "type":"text",
            "text":"May I help you?"
        }
    ]
}' https://api.line.me/v2/bot/message/reply

ユーザ、グループ、トークルームからのイベントに返信するAPIです。
Webhookで通知されたイベントの中で、返信可能なイベントにはreplyTokenが付与されています。
このトークンを指定することで、イベントの送信元にメッセージを返信することができます。

replyTokenは一定秒間以内に使用しないと無効になりますので、受信してから可能な限り速く返信してください。
使用回数の上限は1トークンにつき1回までです。

HTTP request

POST https://api.line.me/v2/bot/message/reply

Request headers

Request header Description
Content-Type application/json
Authorization Bearer {Channel Access Token}

Request body

送信するメッセージを表すsend message objectの配列を含めてください。

Field Type Required Description
replyToken String Yes Webhookで受信したreplyToken
messages Array of send message object Yes 送信するメッセージ
最大5件

Response

Response JSONの例

{}

成功時はstatus code 200と共に空のJSONオブジェクトを返します。

Push message

Push messageリクエストの例

curl -X POST \
-H 'Content-Type:application/json' \
-H 'Authorization: Bearer {ENTER_ACCESS_TOKEN}' \
-d '{
    "to": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "messages":[
        {
            "type":"text",
            "text":"Hello, world1"
        },
        {
            "type":"text",
            "text":"Hello, world2"
        }
    ]
}' https://api.line.me/v2/bot/message/push

ユーザ、グループ、トークルームに任意のタイミングでメッセージを送信するAPIです。

HTTP request

POST https://api.line.me/v2/bot/message/push

Request headers

Request Header Description
Content-Type application/json
Authorization Bearer {Channel Access Token}

Request body

送信するメッセージを表すsend message objectの配列を含めてください。

Field Type Required Description
to String Yes 送信先識別子
messages Array of send message object Yes 送信するメッセージ
最大5件

Response

Response JSONの例

{}

成功時はstatus code 200と共に空のJSONオブジェクトを返します。

Multicast

Multicastリクエストの例

curl -X POST \
-H 'Content-Type:application/json' \
-H 'Authorization: Bearer {ENTER_ACCESS_TOKEN}' \
-d '{
    "to": ["xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"],
    "messages":[
        {
            "type":"text",
            "text":"Hello, world1"
        },
        {
            "type":"text",
            "text":"Hello, world2"
        }
    ]
}' https://api.line.me/v2/bot/message/multicast

複数のユーザに任意のタイミングでメッセージを送信するAPIです。

HTTP request

POST https://api.line.me/v2/bot/message/multicast

Request headers

Request header Description
Content-Type application/json
Authorization Bearer {Channel Access Token}

Request body

送信するメッセージを表すsend message objectの配列を含めてください。

Field Type Required Description
to Array of string Yes 送信先識別子
最大150ユーザ
messages Array of send message object Yes 送信するメッセージ
最大5件

Response

Response JSONの例

{}

成功時はstatus code 200と共に空のJSONオブジェクトを返します。

Send message object

送信するメッセージの内容を表すJSONオブジェクトです。

Text

Textの例

{
    "type": "text",
    "text": "Hello, world"
}
Field Type Required Description
type String Yes text
text String Yes メッセージのテキスト
2000文字以内

絵文字を含むtextの例

{
    "type": "text",
    "text": "\uDBC0\uDC84 LINE emoji"
}

メッセージのテキストには以下の絵文字を含めることができます。

Image

Imageの例

{
    "type": "image",
    "originalContentUrl": "https://example.com/original.jpg",
    "previewImageUrl": "https://example.com/preview.jpg"
}
Field Type Required Description
type String Yes image
originalContentUrl String Yes 画像のURL (1000文字以内)
HTTPS
JPEG
縦横最大1024px
最大1MB
previewImageUrl String Yes プレビュー画像のURL (1000文字以内)
HTTPS
JPEG
縦横最大240px
最大1MB

Video

Videoの例

{
    "type": "video",
    "originalContentUrl": "https://example.com/original.mp4",
    "previewImageUrl": "https://example.com/preview.jpg"
}
Field Type Required Description
type String Yes video
originalContentUrl String Yes 動画ファイルのURL (1000文字以内)
HTTPS
mp4
長さ1分以下
最大10MB
previewImageUrl String Yes プレビュー画像のURL (1000文字以内)
HTTPS
JPEG
縦横最大240px
最大1MB

Audio

Audioの例

{
    "type": "audio",
    "originalContentUrl": "https://example.com/original.m4a",
    "duration": 240000
}
Field Type Required Description
type String Yes audio
originalContentUrl String Yes 音声ファイルのURL (1000文字以内)
HTTPS
m4a
長さ1分以下
最大10MB
duration Number Yes 音声ファイルの時間長さ(ミリ秒)

Location

Locationの例

{
    "type": "location",
    "title": "my location",
    "address": "〒150-0002 東京都渋谷区渋谷2丁目21−1",
    "latitude": 35.65910807942215,
    "longitude": 139.70372892916203
}
Field Type Required Description
type String Yes location
title String Yes タイトル
100文字以内
address String Yes 住所
100文字以内
latitude Decimal Yes 緯度
longitude Decimal Yes 経度

Sticker

Stickerの例

{
  "type": "sticker",
  "packageId": "1",
  "stickerId": "1"
}

Messaging APIから送信できるStickerの識別子は以下を参照ください。
Sticker一覧

Field Type Required Description
type String Yes sticker
packageId String Yes パッケージ識別子
stickerId String Yes Sticker識別子

Imagemap message

Imagemapはリンク付きの画像コンテンツです。画像全体を1つのリンクとしたり、画像の複数の領域に異なるリンクURLを指定することもできます。

左右2つのタップ領域を持つImagemap

{
  "type": "imagemap",
  "baseUrl": "https://example.com/bot/images/rm001",
  "altText": "this is an imagemap",
  "baseSize": {
      "height": 1040,
      "width": 1040
  },
  "actions": [
      {
          "type": "uri",
          "linkUri": "https://example.com/",
          "area": {
              "x": 0,
              "y": 0,
              "width": 520,
              "height": 1040
          }
      },
      {
          "type": "message",
          "text": "hello",
          "area": {
              "x": 520,
              "y": 0,
              "width": 520,
              "height": 1040
          }
      }
  ]
}
Field Type Required Description
type String Yes imagemap
baseUrl String Yes Imagemapに使用する画像のbase URL (1000文字以内)
HTTPS
altText String Yes 代替テキスト
400文字以内
baseSize.width Number Yes 基本比率サイズの幅(1040を指定してください)
baseSize.height Number Yes 基本比率サイズの高さ(幅を1040としたときの高さを指定してください)
actions Array of imagemap action object Yes タップ時のアクション
50以内

Base URL

Imagemapに使用する画像は、base URLの末尾に、クライアントが要求する解像度を横幅サイズ(px)で付与したURLでダウンロードできるようにしておく必要があります。

例として、base URLに以下を指定した場合、

https://example.com/images/cats

クライアント端末が幅700pxの解像度をダウンロードするURLは以下になります。

https://example.com/images/cats/700

クライアント端末から要求される横幅サイズは以下のいずれかになります。

横幅サイズ(px)
1040, 700, 460, 300, 240

Imagemapに使用できる画像の仕様は以下です。

フォーマット
JPEG または PNG
ファイルサイズ
最大1MB

Imagemap action object

Imagemapに配置するアクションの内容とタップ領域の位置を指定するオブジェクトです。

タップされたときに指定のURIを開くuriと、特定のメッセージ送信をおこなうmessageの2種類があります。

URI action

Field Type Required Description
type String Yes uri
linkUri String Yes WebページのURL
1000文字以内
area Imagemap area object Yes タップ領域の定義

Message action

Field Type Required Description
type String Yes message
text String Yes 送信するメッセージ
400文字以内
area Imagemap area object Yes タップ領域の定義

Imagemap area object

Imagemap全体の幅を1040pxとしたときのサイズを指定します。各座標は左上を原点とします。

Field Type Required Description
x Number Yes タップ領域の横方向の位置
y Number Yes タップ領域の縦方向の位置
width Number Yes タップ領域の幅
height Number Yes タップ領域の高さ

Template message

Template messageは、あらかじめ定義されたレイアウトのテンプレートにカスタムデータを挿入することによって構築するメッセージです。

Botとユーザのインタラクティブなコミュニケーションに役立つ4種類のテンプレートを用意しています。

Field Type Required Description
type String Yes template
template Buttons
Confirm
Carousel
Image Carousel
Yes テンプレートの内容を表すオブジェクト
altText String Yes 代替テキスト
400文字以内

Buttons

Buttonsの例

{
  "type": "template",
  "altText": "this is a buttons template",
  "template": {
      "type": "buttons",
      "thumbnailImageUrl": "https://example.com/bot/images/image.jpg",
      "title": "Menu",
      "text": "Please select",
      "actions": [
          {
            "type": "postback",
            "label": "Buy",
            "data": "action=buy&itemid=123"
          },
          {
            "type": "postback",
            "label": "Add to cart",
            "data": "action=add&itemid=123"
          },
          {
            "type": "uri",
            "label": "View detail",
            "uri": "http://example.com/page/123"
          }
      ]
  }
}

画像、タイトル、テキストと、複数のアクションボタンを組み合わせたテンプレートメッセージです。

Field Type Required Description
type String Yes buttons
thumbnailImageUrl String No 画像のURL (1000文字以内)
HTTPS
JPEGまたはPNG
縦横比 1:1.51
縦横最大1024px
最大1MB
title String No タイトル
40文字以内
text String Yes 説明文
画像もタイトルも指定しない場合:160文字以内
画像またはタイトルを指定する場合:60文字以内
actions Array of template action Yes ボタン押下時のアクション
最大4個

Confirm

Confirmの例

{
  "type": "template",
  "altText": "this is a confirm template",
  "template": {
      "type": "confirm",
      "text": "Are you sure?",
      "actions": [
          {
            "type": "message",
            "label": "Yes",
            "text": "yes"
          },
          {
            "type": "message",
            "label": "No",
            "text": "no"
          }
      ]
  }
}

2つのアクションボタンを提示するテンプレートメッセージです。

Field Type Required Description
type String Yes confirm
text String Yes 説明文
240文字以内
actions Array of template action Yes ボタン押下時のアクション
左右2つのアクションを指定する

Carouselの例

{
  "type": "template",
  "altText": "this is a carousel template",
  "template": {
      "type": "carousel",
      "columns": [
          {
            "thumbnailImageUrl": "https://example.com/bot/images/item1.jpg",
            "title": "this is menu",
            "text": "description",
            "actions": [
                {
                    "type": "postback",
                    "label": "Buy",
                    "data": "action=buy&itemid=111"
                },
                {
                    "type": "postback",
                    "label": "Add to cart",
                    "data": "action=add&itemid=111"
                },
                {
                    "type": "uri",
                    "label": "View detail",
                    "uri": "http://example.com/page/111"
                }
            ]
          },
          {
            "thumbnailImageUrl": "https://example.com/bot/images/item2.jpg",
            "title": "this is menu",
            "text": "description",
            "actions": [
                {
                    "type": "postback",
                    "label": "Buy",
                    "data": "action=buy&itemid=222"
                },
                {
                    "type": "postback",
                    "label": "Add to cart",
                    "data": "action=add&itemid=222"
                },
                {
                    "type": "uri",
                    "label": "View detail",
                    "uri": "http://example.com/page/222"
                }
            ]
          }
      ]
  }
}

複数の情報を並べて提示できるカルーセル型のテンプレートメッセージです。

Field Type Required Description
type String Yes carousel
columns Array of column object Yes カラムの配列
最大5個
Field Type Required Description
thumbnailImageUrl String No 画像のURL (1000文字以内)
HTTPS
JPEGまたはPNG
縦横比 1:1.51
縦横最大1024px
最大1MB
title String No タイトル
40文字以内
text String Yes 説明文
画像もタイトルも指定しない場合:120文字以内
画像またはタイトルを指定する場合:60文字以内
actions Array of template action Yes ボタン押下時のアクション
最大3個

Image Carouselの例

{
  "type": "template",
  "altText": "this is a image carousel template",
  "template": {
      "type": "image_carousel",
      "columns": [
          {
            "imageUrl": "https://example.com/bot/images/item1.jpg",
            "action": {
              "type": "postback",
              "label": "Buy",
              "data": "action=buy&itemid=111"
            }
          },
          {
            "imageUrl": "https://example.com/bot/images/item2.jpg",
            "action": {
              "type": "message",
              "label": "Yes",
              "text": "yes"
            }
          },
          {
            "imageUrl": "https://example.com/bot/images/item3.jpg",
            "action": {
              "type": "uri",
              "label": "View detail",
              "uri": "http://example.com/page/222"
            }
          }
      ]
  }
}

複数の画像を並べて提示できるカルーセル型のテンプレートメッセージです。

Field Type Required Description
type String Yes image_carousel
columns Array of column object Yes カラムの配列
最大5個
Field Type Required Description
imageUrl String Yes 画像のURL (1000文字以内)
HTTPS
JPEGまたはPNG
縦横比 1:1
縦横最大1024px
最大1MB
action template action Yes 画像をタップした時のアクション

Template action

テンプレートメッセージに付加するアクションです。

Postback action

このアクションをタップすると、dataで指定された文字列がpostback eventとしてwebhookで通知されます。

textを指定した場合、その内容がユーザの発言として同時に送信されます。

Field Type Required Description
type String Yes postback
label String Yes/No アクションの表示名
Image Carousel以外の場合:20文字以内(必須)
Image Carouselの場合:12文字以内(省略可能)
data String Yes Webhookにpostback eventpostback.dataプロパティとして送信される文字列データ
300文字以内
text String No アクション実行時に送信されるテキスト
300文字以内

Message action

このアクションをタップすると、textで指定された文字列がユーザの発言として送信されます。

Field Type Required Description
type String Yes message
label String Yes/No アクションの表示名
Image Carousel以外の場合:20文字以内(必須)
Image Carouselの場合:12文字以内(省略可能)
text String Yes アクション実行時に送信されるテキスト
300文字以内

URI action

このアクションをタップすると、uriで指定されたURIを開きます。

Field Type Required Description
type String Yes uri
label String Yes/No アクションの表示名
Image Carousel以外の場合:20文字以内(必須)
Image Carouselの場合:12文字以内(省略可能)
uri String Yes アクション実行時に開くURI (1000文字以内)
http, https, tel

Datetime picker action

このアクションをタップすると日付や時刻を選択するダイアログが表示され、ユーザが選択した日付や時刻がpostback eventとしてwebhookで通知されます。

Field Type Required Description
type String Yes datetimepicker
label String Yes/No アクションの表示名
Image Carousel以外の場合:20文字以内(必須)
Image Carouselの場合:12文字以内(省略可能)
data String Yes Webhookにpostback eventpostback.dataプロパティとして送信される文字列データ
300文字以内
mode String Yes 動作モード
date:日付を選択する
time:時刻を選択する
datetime:日付と時刻を選択する
initial String No 日付や時刻の初期値
max String No 選択可能な日付や時刻の最大値
min以後の値である必要があります。
min String No 選択可能な日付や時刻の最小値
max以前の値である必要があります。
Date and time format

initial, maxおよびminで指定する日付や時刻のフォーマットは以下の通りです。
以下の表における full-date, time-hour および time-minute はRFC3339で定義されている形式です。

mode format example
date full-date
最大:2100-12-31
最小:1900-01-01
2017-06-18
time time-hour “:” time-minute
最大:23:59
最小:00:00
00:00
06:15
23:59
datetime full-date (“T” \ “t”) time-hour “:” time-minute
最大:2100-12-31T23:59
最小:1900-01-01T00:00

Content

Contentリクエストの例

curl -X GET \
-H 'Authorization: Bearer {ENTER_ACCESS_TOKEN}' \
https://api.line.me/v2/bot/message/{messageId}/content

ユーザから送信された画像、動画、音声にアクセスするAPIです。

HTTP request

GET https://api.line.me/v2/bot/message/{messageId}/content

Request headers

Request header Description
Authorization Bearer {Channel Access Token}

URL parameters

Parameter Description
messageId メッセージの識別子

Response

成功時はstatus code 200と共にコンテンツのバイナリデータを返します。

Profile

Profileリクエストの例

curl -X GET \
-H 'Authorization: Bearer {ENTER_ACCESS_TOKEN}' \
https://api.line.me/v2/bot/profile/{userId}

ユーザのプロフィール情報を取得するAPIです。

HTTP request

GET https://api.line.me/v2/bot/profile/{userId}

Request headers

Request header Description
Authorization Bearer {Channel Access Token}

URL parameters

Parameter Description
userId ユーザ識別子

Response

Response bodyの例

{
    "displayName":"LINE taro",
    "userId":"Uxxxxxxxxxxxxxx...",
    "pictureUrl":"http://obs.line-apps.com/...",
    "statusMessage":"Hello, LINE!"
}

成功時はstatus code 200と共に以下のパラメータを持つJSONオブジェクトを返します。

Field Type Description
displayName String 表示名
userId String ユーザ識別子
pictureUrl String プロフィール画像 URL。ユーザーが登録していないとレスポンス JSON に含まれません。
statusMessage String ユーザーのステータスメッセージ。 ユーザーが登録していないとレスポンス JSON に含まれません。

Get Group/Room member profile

Group/Room member profileリクエストの例

curl -X GET \
-H 'Authorization: Bearer {ENTER_ACCESS_TOKEN}' \
https://api.line.me/v2/bot/group/{groupId}/member/{userId}

Botアカウントと同じグループまたはトークルームに参加しているユーザのプロフィール情報を取得するAPIです。

Botアカウントと友だちになっていないユーザーやブロックしているユーザーでも、同じグループまたはトークルームに参加していればプロフィール情報の取得が可能です。

HTTP request

GET https://api.line.me/v2/bot/group/{groupId}/member/{userId}

GET https://api.line.me/v2/bot/room/{roomId}/member/{userId}

Request headers

Request header Description
Authorization Bearer {Channel Access Token}

URL parameters

Group

Parameter Description
groupId グループの識別子
userId ユーザ識別子

Room

Parameter Description
roomId トークルームの識別子
userId ユーザ識別子

Response

Response bodyの例

{
    "displayName":"LINE taro",
    "userId":"Uxxxxxxxxxxxxxx...",
    "pictureUrl":"http://obs.line-apps.com/..."
}

成功時はstatus code 200と共に以下のパラメータを持つJSONオブジェクトを返します。

Field Type Description
displayName String 表示名
userId String ユーザ識別子
pictureUrl String 画像URL

Get Group/Room member IDs

Group/Room member IDsリクエストの例

curl -X GET \
-H 'Authorization: Bearer {ENTER_ACCESS_TOKEN}' \
https://api.line.me/v2/bot/group/{groupId}/members/ids?start={continuationToken}

Botアカウントと同じグループまたはトークルームに参加しているユーザのuserIdを取得するAPIです。

Botアカウントと友だちになっていないユーザーやブロックしているユーザーでも、同じグループまたはトークルームに参加していればuserIdの取得が可能です。

HTTP request

GET https://api.line.me/v2/bot/group/{groupId}/members/ids?start={continuationToken}

GET https://api.line.me/v2/bot/room/{roomId}/members/ids?start={continuationToken}

Request headers

Request header Description
Authorization Bearer {Channel Access Token}

URL parameters

Group

Parameter Required Description
groupId Yes グループの識別子
start No continuationToken

Room

Parameter Required Description
roomId Yes トークルームの識別子
start No continuationToken

Response

Response bodyの例

{"memberIds":["Uxxxxxxxxxxxxxx...","Uxxxxxxxxxxxxxx...","Uxxxxxxxxxxxxxx..."]}

{"memberIds":["Uxxxxxxxxxxxxxx...","Uxxxxxxxxxxxxxx...","Uxxxxxxxxxxxxxx..."],"next":"jxEWCEEP..."}

成功時はstatus code 200と共に以下のパラメータを持つJSONオブジェクトを返します。

Property Type Required Description
memberIds Array of string Yes グループまたはトークルームに参加しているユーザのuserIdのリスト
最大100件
next String No continuationToken
memberIdsに続きがある場合にのみセットされます。

Leave

Leaveリクエストの例

curl -X POST \
-H 'Authorization: Bearer {ENTER_ACCESS_TOKEN}' \
https://api.line.me/v2/bot/room/{roomId}/leave

グループまたはトークルームから退出するAPIです。

HTTP request

POST https://api.line.me/v2/bot/group/{groupId}/leave

POST https://api.line.me/v2/bot/room/{roomId}/leave

Request headers

Request header Description
Authorization Bearer {Channel Access Token}

URL parameters

Parameter Description
groupId グループの識別子
roomId トークルームの識別子

Response

Response JSONの例

{}

成功時はstatus code 200と共に空のJSONオブジェクトを返します。

LINE Beacon

LINE Beacon は、「連携しているLINEユーザがビーコンデバイスの受信圏内に出入りしたことなどをwebhookで即座にbotが知ることができる」サービスです。

特別なビーコンデバイスとLINEユーザの相対的な位置関係を使い、特定のLINEユーザに対して特別なサービスを提供することがより簡単に実現できるようになります。

Connecting your bot with Beacon

LINE@ MANAGER (LINE Official Account Manager)でビーコンとbotアカウントを結びつけてください。

Receiving webhooks from a LINE user

  1. LINEがインストールされているスマートフォンの bluetoothをonにしてください
  2. 「LINE Beaconを利用」にチェックを入れてください
    • LINE -> 設定 -> プライバシー管理 -> 「LINE Beaconを利用」
  3. Botアカウントを友達に追加してください
    • Botアカウントと連携していないLINEユーザの情報は送られません。
  4. ビーコンデバイスの電源が入っていることを確認し、スマートフォンを近づけて下さい。
    • LINEアプリがビーコンを検知し、その情報をLINEプラットフォームに送信します。

Bringing information together with Beacon Banner

ビーコンデバイス付近のユーザのfriend listとtalk list 上に専用のバナー(Beacon Banner)を表示させる施策を、一部の店舗/建物で実施しています。

Beacon Banner をタップすると、「2. LINE Beacon を利用」と「3. 友だち追加」を同時に行うことができ、ビーコンによる友だち追加とメッセージ配信をワンストップで行うことが可能となります。

Example of Beacon Banner
(図中の緑色の帯が「Beacon Banner」です)

こちらの機能の利用をご希望の際は、LINE Partner よりお問い合わせ下さい。

Partner APIs

Issue Channel access token

Issue Channel access token の例

curl -X POST  \
-H "Content-Type:application/x-www-form-urlencoded" \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode 'client_id={ENTER_CLIENT_ID}' \
--data-urlencode 'client_secret={ENTER_CLIENT_SECRET}' \
https://api.line.me/v2/oauth/accessToken

HTTP request

POST https://api.line.me/v2/oauth/accessToken

Request header

Item Description
Content-Type application/x-www-form-urlencoded

Request body

Request body は form-urlencoded フォーマットになります。

Name Type Description
grant_type String 「client_credentials」固定
client_id String Channel ID を入力します。Channel Console から確認できます。
client_secret String Channel secret を入力します。Channel Console から確認できます。

Response

Response JSONの例

{
"access_token":"W1TeHCgfH2Liwa.....",
"expires_in":2592000,
"token_type":"Bearer"
}

成功時はHTTPステータス200と共に、以下のフィールドを持つJSONを返却します。

Property Type Description
token_type String 「Bearer」固定
access_token String Channel access token
expires_in Integer Channel access token の有効期限です。Access tokenの発行からの秒数になります。

Error response JSONの例

{
"error":"invalid_request",
"error_description":"some parameters missed or invalid"
}

Error

エラー発生時はHTTPステータス400と共に、以下のフィールドを持つJSONを返却します。

Property Type Description
error String エラーの概要
error_description String 詳細なエラー内容。レスポンスJSONに含まれない場合もあります。

Revoke Channel access token

Revoke Channel access token の例

curl -X POST \
-H "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode 'access_token={ENTER_ACCESS_TOKEN}' \
https://api.line.me/v2/oauth/revoke

Messaging APIで利用するChannel access tokenを無効化します。

HTTP request

POST https://api.line.me/v2/oauth/revoke

Request header

Item Description
Content-Type application/x-www-form-urlencoded

Request body

Request body は form-urlencoded フォーマットになります。

Name Type Description
access_token String Channel access token

Response

成功時はHTTPステータス200と共に、空のResponse bodyを返します。
既に無効化されたChannel access tokenが指定された場合も、エラーにはなりません。

Error response JSONの例

{
"error":"invalid_request",
"error_description":"some parameters missed or invalid"
}

Error

エラー発生時はHTTPステータス400と共に、以下のフィールドを持つJSONを返却します。

Property Type Description
error String エラーの概要
error_description String 詳細なエラー内容。レスポンスJSONに含まれない場合もあります。

Mission Stickers

Mission Stickersリクエストの例

curl -X POST \
-H 'Content-Type: application/json' \
-H 'X-Line-ChannelId:{ENTER_CHANNEL_ID}' \
-H 'X-Line-ChannelSecret: {ENTER_CHANNEL_SECRET}' \
-H 'X-Line-Trusted-User-With-ACL: {ENTER_TRUSTED_USER}' \
-d '{
"to": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  "messages": [
    {
      "packageId": "0000",
      "isPresent": false
    } 
  ]
}'
https://api.line.me/v2/missionSticker/send

ミッションスタンプ(Mission Stickers)とは、ある特定の条件をクリアしたユーザに対して、特定のスタンプを利用可能にする事ができるサービスです。

HTTP request

POST https://api.line.me/v2/missionSticker/send

Request headers

Item Description
Content-Type application/json
X-Line-ChannelId Channel ID を入力します。Channel Console から確認できます。
X-Line-ChannelSecret Channel secret を入力します。Channel Console から確認できます。
X-Line-Trusted-User-With-ACL API利用権限の発行時にご連絡する値を入力します。

Request body

Request bodyはjsonフォーマットになります。

Name Type Description
to String 送信先識別子
messages Array packageIdとisPresentを含むオブジェクトの配列。1個のみ指定可能。
messages[].packageId String パッケージ識別子
messages[].isPresent Boolean false

Response

Response JSONの例

{"ticketId":"AB1234-1234567890"}

レスポンスはJSON フォーマットで返却されます。

Property Type Description
ticketId String LINEの内部で使われる値。
ticketIdがレスポンスされた場合、APIリクエストは成功しています。

Error

Property Type Description
message String エラー内容

Error response

message Description
authentication failed 以下のいずれか、または両方
・リクエストヘッダのX-Line-ChannelId, X-Line-ChannelSecret, X-Line-Trusted-User-With-ACL に設定している値のいずれかが間違っている。
・APIコールを行うサーバが"Server IP Whitelist"に登録されていない。
CHANNEL_MISSION_STICKER_NOT_USABLE ミッションスタンプAPIの利用権限が付与されていない。

Get followers IDs

Get followers IDsリクエストの例

curl -X GET \
-H 'Authorization: Bearer {ENTER_ACCESS_TOKEN}' \
https://api.line.me/v2/bot/followers/ids?start={continuationToken}

Botを友だち追加しているユーザのuserIdを取得するAPIです。

HTTP request

GET https://api.line.me/v2/bot/followers/ids?start={continuationToken}

Request headers

Request header Description
Content-Type application/json
Authorization Bearer Channel Access Token

URL parameters

Parameter Required Description
start No continuationToken

Response

Response JSONの例

{"userIds":["Uxxxxxxxxxxxxxx...","Uxxxxxxxxxxxxxx...","Uxxxxxxxxxxxxxx..."]}


{"userIds":["Uxxxxxxxxxxxxxx...","Uxxxxxxxxxxxxxx...","Uxxxxxxxxxxxxxx..."],"next":"yANU9IA..."}

成功時はstatus code 200と共に以下のパラメータを持つJSONオブジェクトを返します。

Property Type Required Description
userIds Array of string Yes Botを友だちにしているユーザのuserIdのリスト
最大1000件
next String No continuationToken
userIdsに続きがある場合にのみセットされます。

Social REST API

How to use the APIs

RESTFul API を利用するには Access Token の発行が必要になります。

Validating access tokens

Validate access token の例

curl -X POST \
-H 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'access_token={ENTER_ACCESS_TOKEN}' \
https://api.line.me/v2/oauth/verify

取得した access token を validation するために利用します。

HTTP request

POST https://api.line.me/v2/oauth/verify

Request header

Item Description
Content-Type application/x-www-form-urlencoded

Request body

Request body は form-urlencoded フォーマットになります。

Name Type Description
access_token String 取得した Access Token

Response

Response JSONの例

{
   "scope":"P",
   "client_id":"1350031035",
   "expires_in":2591965
}

レスポンスはJSON フォーマットで返却されます。

Property Type Description
scope String Access token に付与されている権限です。
client_id String Access token が発行された Channel ID です。
expires_in Integer Access token の有効期限です。API をコールしてからの残りの秒数となります。

Refreshing access tokens

Refresh access token の例

curl -X POST \
-H 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=refresh_token' \
--data-urlencode 'client_id={ENTER_CLIENT_ID}' \
--data-urlencode 'client_secret={ENTER_CLIENT_SECRET}' \
--data-urlencode 'refresh_token={ENTER_REFRESH_TOKEN}' \
https://api.line.me/v2/oauth/accessToken

HTTP request

POST https://api.line.me/v2/oauth/accessToken

Request header

Item Description
Content-Type application/x-www-form-urlencoded

Request body

Request body は form-urlencoded フォーマットになります。

Name Type Description
grant_type String 「refresh_token」固定
refresh_token String 再発行する access token の refresh token を入力します。
client_id String Channel ID を入力します。Channel Console から確認できます。
client_secret String Channel secret を入力します。Channel Console から確認できます。

Response

Response JSONの例

{
   "token_type":"Bearer",
   "scope":"P",
   "access_token":"bNl4YEFPI/hjFWhTqexp4MuEw...",
   "expires_in":2591977,
   "refresh_token":"8iFFRdyxNVNLWYeteMMJ"
}

レスポンスはJSON フォーマットで返却されます。

Property Type Description
token_type String 「Bearer」固定
scope String Access token に付与されている権限です。
access_token String Access token
expires_in Integer Access token の有効期限です。Access tokenの発行からの秒数になります。
refresh_token String Access token の再発行に利用します。Access token の有効期限から10日間有効です。

Revoking tokens

Revoke token の例

curl -X POST \
-H 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'refresh_token={ENTER_REFRESH_TOKEN}' \
https://api.line.me/v2/oauth/revoke

HTTP request

POST https://api.line.me/v2/oauth/revoke

Request header

Item Description
Content-Type application/x-www-form-urlencoded

Request body

Request body は form-urlencoded フォーマットになります。

Name Type Description
refresh_token String 無効化させる access token の refresh token を入力します。

Response

Response JSONの例

{}

レスポンスは HTTP 200 で返却されます。エラーレスポンスはありません。

Getting user profiles

Profile リクエストの例

curl -X GET \
-H 'Authorization: Bearer {ENTER_ACCESS_TOKEN}' \
https://api.line.me/v2/profile

ユーザーの表示名、プロフィール画像とステータスメッセージを取得することができます。

HTTP request

GET https://api.line.me/v2/profile

Request header

Item Description
Authorization Bearer {ACCESS_TOKEN}

Response

Response JSONの例

{
  "userId":"Ufr47556f2e40dba2456887320ba7c76d",
  "displayName":"Brown",
  "pictureUrl":"https://example.com/abcdefghijklmn",
  "statusMessage":"Hello, LINE!"
}

レスポンスはJSON フォーマットで返却されます。

Property Type Description
displayName String ユーザーの表示名
userId String ユーザー識別ID
pictureUrl String プロフィール画像 URL。 “https” の画像 URL になります。 ユーザーが登録していないとレスポンス JSON に含まれません。
statusMessage String ユーザーのステータスメッセージ。 ユーザーが登録していないとレスポンス JSON に含まれません。

Profile image thumbnails

large の 画像を取得するためにアクセスするURLの例

https://obs.line-apps.com/abcdefghijklmn/large

ユーザーのプロフィール画像を取得時に URLに Suffix を追加することで画像のサイズを変更できます。

Image size Suffix
200 x 200 /large
51 x 51 /small

Error response

エラー発生時には以下のエラーが返却されます。

HTTP status Description
200 OK リクエスト成功
400 Bad Request リクエストに問題があります。リクエストパラメータやJSONのフォーマットを確認してください。
401 Unauthorized Authorizationヘッダを正しく送信していることを確認してください。
403 Forbidden APIの利用権限がありません。ご契約中のプランやアカウントに付与された権限を確認してください。
429 Too Many Requests アクセス頻度を制限内に抑えてください。
500 Internal Server Error APIサーバ側の一時的なエラーです。

Android SDK

LineApiError

Class

Package com.linecorp.linesdk
Extends Object
Implements Parcelable

Methods

getHttpResponseCode()

APIエラーに関連したレスポンスコードを取得します。

戻り値

レスポンスコードを返します。

getMessage()

APIエラーに関連したエラーメッセージを取得します。

戻り値

エラーメッセージを返します。

LineAccessToken

Class

Package com.linecorp.linesdk
Extends Object
Implements Parcelable

Methods

getAccessToken()

access tokenを取得します。

戻り値

access tokenを返します。

getEstimatedExpirationTimeMillis()

access tokenが無効になるUNIX時間を取得します。
UNIX時間は端末にキャッシュされた値から計測されているため、正確ではない可能性があります。

戻り値

access tokenが無効になるUNIX時間を返します。

getExpiresInMillis()

access tokenが無効になるまでの時間(ミリ秒)を取得します。

戻り値

access tokenが無効になるまでの時間(ミリ秒)を返します。

getIssuedClientTimeMillis()

access tokenの取得・リフレッシュ・verifyを最後にしたUNIX時間を取得します。

戻り値

access tokenの取得・リフレッシュ・verifyを最後にしたUNIX時間を返します。

LineApiClient

Interface

Package com.linecorp.linesdk.api

Methods

getCurrentAccessToken()

SDKで使用しているユーザのaccess tokenを取得します。

戻り値

API呼び出しに成功すると、ユーザのaccess token を保持しているLineAccessTokenを含むLineApiResponseを返します。
API呼び出しに失敗すると、nullのLineAccessTokenを含むLineApiResponseを返します。

getProfile()

ユーザのプロフィール情報を取得します。

戻り値

API呼び出しに成功すると、ユーザのプロフィールを保持しているLineProfileを含むLineApiResponseを返します。
API呼び出しに失敗すると、nullのLineProfileを含むLineApiResponseを返します。

logout()

SDKで使用しているユーザのaccess tokenを無効にします。

戻り値

API呼び出し結果を含むLineApiResponseを返します。

refreshAccessToken()

SDKで使用しているユーザのaccess tokenを更新します。

戻り値

API呼び出しに成功すると、更新されたaccess tokenを保持しているLineAccessTokenを含むLineApiResponseを返します。
API呼び出しに失敗すると、nullのLineAccessTokenを含むLineApiResponseを返します。

verifyToken()

SDKで使用しているユーザのaccess tokenが有効か、確認します。

戻り値

access tokenが有効の場合、access tokenを保持しているLineCredentialを含むLineApiResponseを返します。
access tokenが無効の場合、nullのLineCredentialを含むLineApiResponseを返します。

LineApiClientBuilder

Class

Package com.linecorp.linesdk.api
Extends None
Implements None

Constructor

パラメータ

Parameter Description
context Android context
channelId Channel ID

Methods

build()

LineApiClientインスタンスを生成します。

戻り値

LineApiClientインスタンスを返します。

disableTokenAutoRefresh()

access tokenを自動更新する機能を無効にします。

戻り値

LineApiClientBuilderインスタンスを返します。

LineApiResponse

Class

Package com.linecorp.linesdk
Extends Object
Implements None

Methods

getErrorData()

API エラーが発生した場合、エラー情報を取得します。
このメソッドはAPI呼び出しに失敗した場合にのみ使用します。

戻り値

発生したエラー情報を含むLineApiErrorを返します。
API エラーが発生した場合、エラー情報を含むLineApiErrorを返します。
API エラーが発生していない場合、LineApiErrorを返しますが、有効な情報は含まれていません。

getResponseCode()

API呼び出しが正常に完了した場合、レスポンスコードを取得します。

戻り値

API呼び出しが正常に完了した場合、LineApiResponseCodeを返します。

getResponseData()

レスポンス情報が存在する場合、情報を取得します。
レスポンス情報が存在しない場合、NoSuchElementExceptionがthrowされます。
レスポンス情報を取得する前には、isSuccess()を呼び出して、API呼び出しが正常に終了しているか確認してください。

戻り値

LineApiResponseに含まれるレスポンス情報を返却します。

isNetworkError()

Network errorにより、API呼び出しが失敗したかを確認します。

戻り値

Network errorにより、API呼び出しが失敗した場合、trueを返します。
Network error以外の原因で、API呼び出しが失敗した場合、falseを返します。

isServerError()

Server errorにより、API呼び出しが失敗したかを確認します。

戻り値

Server errorにより、API呼び出しが失敗した場合、trueを返します。
Server error以外の原因で、API呼び出しが失敗した場合、falseを返します。

isSuccess()

API呼び出しが成功したかを確認します。

戻り値

API呼び出しが成功した場合、trueを返します。
API呼び出しが失敗した場合、falseを返します。

LineCredential

Class

Package com.linecorp.linesdk
Extends Object
Implements Parcelable

Methods

getAccessToken()

ユーザのaccess tokenを取得します。

戻り値

ユーザのaccess tokenを含むLineAccessTokenを返します。

getPermission()

ユーザのaccess tokenに付与されている権限を取得します。

戻り値

ユーザのaccess tokenに付与されている権限のコードを返します。
権限のコードは以下のとおりです。

Permission code Description
P PROFILE / LINEユーザーのプロフィール情報を取得するための権限

LineLoginApi

Class

Package com.linecorp.linesdk.auth
Extends None
Implements None

Methods

getLoginIntent()

LINEログインを行うためのインテントを取得します。
端末にLINEアプリがインストールされている場合は、app-to-appのLINEログインが行われます。
端末にLINEアプリがインストールされていない場合は、ブラウザを利用したLINEログインが行われます。

パラメータ

Parameter Description
context Android context
channelId Channel ID

戻り値

LINEログインを行うためのインテントを返します。

getLoginIntentWithoutLineAppAuth()

ブラウザを利用したLINEログインを行うためのインテントを取得します。

パラメータ

Parameter Description
context Android context
channelId Channel ID

戻り値

ブラウザを利用したLINEログインを行うためのインテントを返します。

LineLoginResult

Class

Package com.linecorp.linesdk.auth
Extends Object
Implements Parcelable

Methods

isSuccess()

LINEログインが成功したかを確認します。

戻り値

LINEログインが成功した場合、trueを返します。
LINEログインが失敗した場合、falseを返します。

getResponseCode()

LINEログインが成功したかどうかを識別するレスポンスコードを取得します。

戻り値

LINEログインが成功したかどうかを識別するLineApiResponseCodeを返します。

getLineProfile()

ユーザのプロフィール情報を取得します。

戻り値

ユーザのプロフィール情報を含むLineProfileを返します。

getLineCredential()

ユーザが認証で利用する情報を取得します。

戻り値

ユーザが認証で利用する情報が含むLineCredentialを返します。

getErrorData()

ログイン時に発生したエラー情報を取得します。
このメソッドはログインに失敗した場合にのみ呼び出してください。

戻り値

ログインに失敗した場合に、エラー情報を含むLineApiErrorを返します。
エラー情報がない場合にも、LineApiErrorを返しますが、有効な情報は含まれていません。

LineProfile

Class

Package: com.linecorp.linesdk
Extends: Object
Implements: Parcelable

Methods

getDisplayName()

ユーザーの表示名を取得します。

戻り値

ユーザーの表示名を返します。

getPictureUrl()

ユーザのプロフィール画像 URLを取得します。

戻り値

ユーザのプロフィール画像 URLを返します。

ユーザーのプロフィール画像を取得時に URLに Suffix を追加することで画像のサイズを変更できます。

Image Size Suffix
200 x 200 /large
51 x 51 /small

getStatusMessage()

ユーザのステータスメッセージを取得します。

戻り値

ユーザのステータスメッセージを返します。

getUserId()

ユーザのユーザー識別IDを取得します。

戻り値

ユーザのユーザー識別IDを返します。

iOS SDK

LineSDKAPI

Class

Superclass NSObject
Declared in LineSDKAPI.h

Methods

initWithConfiguration

Method prototype

- (instancetype)initWithConfiguration:(LineSDKConfiguration *)configuration NS_DESIGNATED_INITIALIZER;

LineSDKConfigurationを使って、LineSDKAPIを初期化します。

currentAccessToken

Method prototype

- (nullable LineSDKAccessToken *)currentAccessToken;

access tokenを取得します。

戻り値

access tokenを含むLineSDKAccessTokenを返します。
有効なaccess tokenが存在しない場合は、nilを返します。

getProfileWithCallbackQueue:completion

Method prototype

- (void)getProfileWithCallbackQueue:(dispatch_queue_t)queue completion:(LineSDKAPIGetProfileCompletion)completion NS_SWIFT_NAME(getProfile(queue:completion:));

ユーザのプロフィール情報を取得します。
completion blockで実行するdispatch queueを指定します。
queueパラメータにdispatch queueを設定します。

パラメータ

Parameter Description
queue completion blockで実行するdispatch queue
値がnilの場合は、completion blockは、main queueで実行されます。
completion ユーザのプロフィール情報を取得後に呼び出されるCompletion block

Completion block arguments

Argument Description
profile ユーザのプロフィール情報
error API呼び出しで発生したエラー。正常に終了の場合はnil

getProfileWithCompletion

Method prototype

- (void)getProfileWithCompletion:(void(^)(LineSDKProfile * _Nullable profile, NSError * _Nullable error))completion NS_SWIFT_NAME(getProfile(completion:));

ユーザのプロフィール情報を取得します。

パラメータ

Parameter Description
completion ユーザのプロフィール情報を取得後に呼び出されるCompletion block

Completion block arguments

Argument Description
profile ユーザのプロフィール情報
error API呼び出しで発生したエラー。正常に終了の場合はnil

logoutWithCompletion

Method prototype

- (void)logoutWithCompletion:(void(^)(BOOL success, NSError * _Nullable error))completion;

ユーザのaccess tokenを無効にします。

パラメータ

Parameter Description
completion ログアウト完了後に呼び出されるCompletion block

Completion block arguments

Argument Description
success ログアウトに成功した場合はYES。ログアウトに失敗した場合NO
error API呼び出しで発生したエラー。正常に終了の場合はnil

refreshTokenWithCallbackQueue:completion

- (void)refreshTokenWithCallbackQueue:(dispatch_queue_t)queue completion:(LineSDKAPITokenRefreshCompletion)completion NS_SWIFT_NAME(refreshToken(queue:completion:));

ユーザのaccess tokenを更新します。
completion blockで実行するdispatch queueを指定します。
queueパラメータにdispatch queueを設定します。

パラメータ

Parameter Description
queue completion blockで実行するdispatch queue
値がnilの場合は、completion blockは、main queueで実行されます。
completion access token更新後に呼び出されるCompletion block

Completion block arguments

Argument Description
accessToken 更新されたaccess token
error API呼び出しで発生したエラー。正常に終了の場合はnil

refreshTokenWithCompletion

Method prototype

- (void)refreshTokenWithCompletion:(void(^)(LineSDKAccessToken * _Nullable accessToken, NSError * _Nullable error))completion;

ユーザのaccess tokenを更新します。

パラメータ

Parameter Description
completion access token更新後に呼び出されるCompletion block

Completion block arguments

Argument Description
accessToken 更新されたaccess token
error API呼び出しで発生したエラー。正常に終了の場合はnil

verifyTokenWithCallbackQueue:Completion

Method prototype

- (void)verifyTokenWithCallbackQueue:(dispatch_queue_t)queue completion:(LineSDKAPIVerifyTokenCompletion)completion NS_SWIFT_NAME(verifyToken(queue:completion));

ユーザのaccess tokenが有効か、確認します。
completion blockで実行するdispatch queueを指定します。
queueパラメータにdispatch queueを設定します。

パラメータ

Parameter Description
queue completion blockで実行するdispatch queue
値がnilの場合は、completion blockは、main queueで実行されます。
completion ユーザのaccess tokenが有効か、確認後に呼び出されるCompletion block

Completion block arguments

Argument Description
result ユーザのaccess tokenが有効か、確認した結果
error API呼び出しで発生したエラー。正常に終了の場合はnil

verifyTokenWithCompletion

Method prototype

- (void)verifyTokenWithCompletion:(void(^)(LineSDKVerifyResult * _Nullable result, NSError * _Nullable error))completion;

ユーザのaccess tokenが有効か、確認します。

パラメータ

Parameter Description
completion ユーザのaccess tokenが有効か、確認後に呼び出されるCompletion block

Completion block arguments

Argument Description
result ユーザのaccess tokenが有効か、確認した結果
error API呼び出しで発生したエラー。正常に終了の場合はnil

LineSDKAccessToken

Class

Superclass NSObject
Declared in LineSDKAccessToken.h

Properties

accessToken

Declaration

@property (nonatomic, copy, readonly) NSString *accessToken;

access tokenを保持しているオブジェクト

expiresIn

Declaration

@property (nonatomic, readonly) NSTimeInterval expiresIn;

access tokenが無効になるまでの時間(ミリ秒)

Methods

estimatedExpiredDate

Method prototype

- (NSDate *)estimatedExpiredDate;

access tokenが無効になるUNIX時間を取得します。
UNIX時間は端末にキャッシュされた値から計測されているため、正確ではない可能性があります。

戻り値

access tokenが無効になるUNIX時間を返します。

LineSDKCredential

Class

Superclass NSObject
Declared in LineSDKAPI.h

Properties

accessToken

Declaration

@property (nonatomic, strong, readonly, nullable) LineSDKAccessToken *accessToken;

access tokenを保持しているオブジェクト

permissions

Declaration

@property (nonatomic, strong, readonly) NSOrderedSet<NSString *> *permissions;

ユーザのaccess tokenに付与されている権限のコード
権限のコードは以下のとおりです。

Permission code Description
P LINEユーザーのプロフィール情報を取得するための権限

LineSDKLogin

Class

Superclass NSObject
Declared in LineSDKLogin.h
Protocols LineSDKLoginDelegate

Properties

configuration

Declaration

@property (nonatomic, strong, readonly) LineSDKConfiguration *configuration;

Channel IDやaccess tokenなどのLINE SDK設定値を保持しています。

Methods

canLoginWithLineApp

Method prototype

- (BOOL)canLoginWithLineApp;

LINEアプリを使ったログインが可能かを確認します。

戻り値

LINEアプリを使ったログインが可能な場合は、YESを返します。
LINEアプリを使ったログインが不可能な場合は、NOを返します。これはLINEアプリが端末にインストールされていないことを意味します。

handleOpenURL

Method prototype

- (BOOL)handleOpenURL:(NSURL *)aURL;

app-to-appのLINEログイン時にLINEアプリから返却される情報を制御するために利用します。
右の例のようにAppDelegateopenURLメソッドを実装してください。

openURL Example

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
return [[LineSDKLogin sharedInstance] handleOpenURL:url];
}

パラメータ

Parameter Description
aURL The URL passed into the openURL call.

戻り値

URLの制御に成功した場合、YESを返します。
URLの制御に失敗した場合、NOを返します。

installLineApp

Method prototype

- (void)installLineApp;

LINEアプリをインストールするためにapp storeに遷移します。

isAuthorized

Method prototype

- (BOOL)isAuthorized;

ログイン済で、access tokenを保持しているかを確認します。

パラメータ

戻り値

access tokenを保持している場合は、YESを返します。これはログイン済であることを意味します。
access tokenを保持していない場合は、NOを返します。

isAuthorizing

Method prototype

- (BOOL)isAuthorizing;

ログイン中かを確認します。

戻り値

ログイン中の場合は、YESを返します。
ログイン中ではない場合は、NOを返します。

sharedInstance

Method prototype

+ (instancetype)sharedInstance;

LineSDKLoginのシングルトン・インスタンスを返します。

startLogin

Method prototype

- (void)startLogin;

LINEログインを行います。
端末にLINEアプリがインストールされている場合は、app-to-appのLINEログインが行われます。
端末にLINEアプリがインストールされていない場合は、ブラウザを利用したLINEログインが行われます。

startWebLoginWithSafariViewController

Method prototype

- (void)startWebLoginWithSafariViewController:(BOOL)useSafariViewControllerIfAvailable;

ブラウザを利用したLINEログインを行います。

パラメータ

Parameter Description
useSafariViewControllerIfAvailable Safari View Controllerを利用したLINEログインを行う場合は、YES
ブラウザを利用したLINEログインを行う場合は、NO

LineSDKConfiguration

Class

Superclass NSObject
Declared in LineSDKConfiguration.h

Properties

channelID

Declaration

@property (nonatomic, strong, readonly) NSString *channelID;

アプリケーションが利用しているchannel idです。
アプリケーションのInfo.plist内のLineSDKConfigの値を読み込みます。

Methods

Method prototype

- (nullable LineSDKAccessToken *)currentAccessToken;

SDKが保持しているaccess tokenを返します。

LineSDKLoginDelegate

Protocol

Extends protocol NSObject
Declared in LineSDKLogin.h

LineSDKLoginからイベントの通知を受け取るためのメソッドを実装します。

Methods

didLogin

- (void)didLogin:(LineSDKLogin *)login
credential:(nullable LineSDKCredential *)credential
profile:(nullable LineSDKProfile *)profile
error:(nullable NSError *)error;

パラメータ

Parameter Description
login LINEログインを行うLineSDKLogin
credential LINEログインで付与された認証情報
profile ユーザのプロフィール情報
error LINEログインで失敗した場合は発生したエラー。正常に終了の場合はnil

LineSDKProfile

Class

Superclass NSObject
Declared in LineSDKProfile.h

Properties

displayName

Declaration

@property (nonatomic, copy, readonly) NSString *displayName;

ユーザーの表示名

pictureURL

Declaration

@property (nonatomic, copy, readonly, nullable) NSURL *pictureURL;

ユーザのプロフィール画像URL

statusMessage

Declaration

@property (nonatomic, copy, readonly, nullable) NSString *statusMessage;

ユーザのステータスメッセージ

userId

Declaration

@property (nonatomic, copy, readonly) NSString *userID;

ユーザのユーザー識別ID

LineSDKVerifyResult

Class

Superclass NSObject
Declared in LineSDKVerifyResult.h

Properties

channelID

Declaration

@property (nonatomic, copy, readonly) NSString *channelID;

アプリケーションが利用しているchannel ID

expiresIn

Declaration

@property (nonatomic, readonly) NSTimeInterval expiresIn;

access tokenが無効になるまでの時間(ミリ秒)

permissions

Declaration

@property (nonatomic, copy, readonly, nullable) NSOrderedSet<NSString *> *permissions;

ユーザのaccess tokenに付与されている権限のコード
権限のコードは以下のとおりです。

Permission code Description
P LINEユーザーのプロフィール情報を取得するための権限