line
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTroubleshooting
故障排查
If requests fail, run or
zero doctor check-connector --env-name LINE_TOKENzero doctor check-connector --url https://api.line.me/v2/bot/info --method GET如果请求失败,请运行或
zero doctor check-connector --env-name LINE_TOKENzero doctor check-connector --url https://api.line.me/v2/bot/info --method GETHow to Use
使用方法
All examples below assume you have set. Authentication uses Bearer token in the Authorization header.
LINE_TOKEN以下所有示例均假设您已设置。认证使用Authorization头中的Bearer令牌。
LINE_TOKENBase URL
基础URL
https://api.line.me
https://api.line.me
1. Get Bot Info
1. 获取机器人信息
Retrieve information about the bot associated with the channel access token.
bash
curl -s "https://api.line.me/v2/bot/info" --header "Authorization: Bearer $LINE_TOKEN" | jq .获取与频道访问令牌关联的机器人信息。
bash
curl -s "https://api.line.me/v2/bot/info" --header "Authorization: Bearer $LINE_TOKEN" | jq .2. Get User Profile
2. 获取用户资料
Retrieve a user's display name, profile image, and status message. Replace with the actual user ID.
USER_IDbash
curl -s "https://api.line.me/v2/bot/profile/USER_ID" --header "Authorization: Bearer $LINE_TOKEN" | jq .获取用户的显示名称、头像和状态消息。将替换为实际用户ID。
USER_IDbash
curl -s "https://api.line.me/v2/bot/profile/USER_ID" --header "Authorization: Bearer $LINE_TOKEN" | jq .3. Get Follower IDs
3. 获取关注者ID列表
Retrieve a list of user IDs that have added the bot as a friend. Supports pagination with parameter.
startbash
curl -s "https://api.line.me/v2/bot/followers/ids?limit=100" --header "Authorization: Bearer $LINE_TOKEN" | jq .For pagination, use the token from the response:
nextbash
curl -s "https://api.line.me/v2/bot/followers/ids?limit=100&start=CONTINUATION_TOKEN" --header "Authorization: Bearer $LINE_TOKEN" | jq .获取已添加机器人为好友的用户ID列表。支持使用参数进行分页。
startbash
curl -s "https://api.line.me/v2/bot/followers/ids?limit=100" --header "Authorization: Bearer $LINE_TOKEN" | jq .分页时,使用响应中的令牌:
nextbash
curl -s "https://api.line.me/v2/bot/followers/ids?limit=100&start=CONTINUATION_TOKEN" --header "Authorization: Bearer $LINE_TOKEN" | jq .4. Send Push Message
4. 发送推送消息
Send a message to a specific user. Replace with the target user ID.
USER_IDWrite to :
/tmp/line_request.jsonjson
{
"to": "USER_ID",
"messages": [
{
"type": "text",
"text": "Hello from the LINE bot!"
}
]
}Then run:
bash
curl -s -X POST "https://api.line.me/v2/bot/message/push" --header "Content-Type: application/json" --header "Authorization: Bearer $LINE_TOKEN" -d @/tmp/line_request.json | jq .向特定用户发送消息。将替换为目标用户ID。
USER_ID写入:
/tmp/line_request.jsonjson
{
"to": "USER_ID",
"messages": [
{
"type": "text",
"text": "Hello from the LINE bot!"
}
]
}然后运行:
bash
curl -s -X POST "https://api.line.me/v2/bot/message/push" --header "Content-Type: application/json" --header "Authorization: Bearer $LINE_TOKEN" -d @/tmp/line_request.json | jq .5. Send Reply Message
5. 发送回复消息
Reply to a user event using a reply token received from a webhook event. Reply tokens expire after a short time.
Write to :
/tmp/line_request.jsonjson
{
"replyToken": "REPLY_TOKEN",
"messages": [
{
"type": "text",
"text": "Thanks for your message!"
}
]
}Then run:
bash
curl -s -X POST "https://api.line.me/v2/bot/message/reply" --header "Content-Type: application/json" --header "Authorization: Bearer $LINE_TOKEN" -d @/tmp/line_request.json | jq .使用从Webhook事件中获取的回复令牌回复用户事件。回复令牌会在短时间后过期。
写入:
/tmp/line_request.jsonjson
{
"replyToken": "REPLY_TOKEN",
"messages": [
{
"type": "text",
"text": "Thanks for your message!"
}
]
}然后运行:
bash
curl -s -X POST "https://api.line.me/v2/bot/message/reply" --header "Content-Type: application/json" --header "Authorization: Bearer $LINE_TOKEN" -d @/tmp/line_request.json | jq .6. Send Multicast Message
6. 发送群发消息
Send the same message to multiple users at once (up to 500 user IDs).
Write to :
/tmp/line_request.jsonjson
{
"to": ["USER_ID_1", "USER_ID_2", "USER_ID_3"],
"messages": [
{
"type": "text",
"text": "This is a multicast message!"
}
]
}Then run:
bash
curl -s -X POST "https://api.line.me/v2/bot/message/multicast" --header "Content-Type: application/json" --header "Authorization: Bearer $LINE_TOKEN" -d @/tmp/line_request.json | jq .同时向多个用户发送相同消息(最多500个用户ID)。
写入:
/tmp/line_request.jsonjson
{
"to": ["USER_ID_1", "USER_ID_2", "USER_ID_3"],
"messages": [
{
"type": "text",
"text": "This is a multicast message!"
}
]
}然后运行:
bash
curl -s -X POST "https://api.line.me/v2/bot/message/multicast" --header "Content-Type: application/json" --header "Authorization: Bearer $LINE_TOKEN" -d @/tmp/line_request.json | jq .7. Send Broadcast Message
7. 发送广播消息
Send a message to all users who have added the bot as a friend.
Write to :
/tmp/line_request.jsonjson
{
"messages": [
{
"type": "text",
"text": "This broadcast goes to all followers!"
}
]
}Then run:
bash
curl -s -X POST "https://api.line.me/v2/bot/message/broadcast" --header "Content-Type: application/json" --header "Authorization: Bearer $LINE_TOKEN" -d @/tmp/line_request.json | jq .向所有已添加机器人为好友的用户发送消息。
写入:
/tmp/line_request.jsonjson
{
"messages": [
{
"type": "text",
"text": "This broadcast goes to all followers!"
}
]
}然后运行:
bash
curl -s -X POST "https://api.line.me/v2/bot/message/broadcast" --header "Content-Type: application/json" --header "Authorization: Bearer $LINE_TOKEN" -d @/tmp/line_request.json | jq .8. Check Message Quota
8. 查看消息配额
Get the monthly message quota for the LINE Official Account.
bash
curl -s "https://api.line.me/v2/bot/message/quota" --header "Authorization: Bearer $LINE_TOKEN" | jq .Check how many messages have been sent this month:
bash
curl -s "https://api.line.me/v2/bot/message/quota/consumption" --header "Authorization: Bearer $LINE_TOKEN" | jq .获取LINE官方账号的月度消息配额。
bash
curl -s "https://api.line.me/v2/bot/message/quota" --header "Authorization: Bearer $LINE_TOKEN" | jq .查看本月已发送的消息数量:
bash
curl -s "https://api.line.me/v2/bot/message/quota/consumption" --header "Authorization: Bearer $LINE_TOKEN" | jq .9. Send Image Message
9. 发送图片消息
Send an image to a user.
Write to :
/tmp/line_request.jsonjson
{
"to": "USER_ID",
"messages": [
{
"type": "image",
"originalContentUrl": "https://example.com/image.jpg",
"previewImageUrl": "https://example.com/image_preview.jpg"
}
]
}Then run:
bash
curl -s -X POST "https://api.line.me/v2/bot/message/push" --header "Content-Type: application/json" --header "Authorization: Bearer $LINE_TOKEN" -d @/tmp/line_request.json | jq .向用户发送图片。
写入:
/tmp/line_request.jsonjson
{
"to": "USER_ID",
"messages": [
{
"type": "image",
"originalContentUrl": "https://example.com/image.jpg",
"previewImageUrl": "https://example.com/image_preview.jpg"
}
]
}然后运行:
bash
curl -s -X POST "https://api.line.me/v2/bot/message/push" --header "Content-Type: application/json" --header "Authorization: Bearer $LINE_TOKEN" -d @/tmp/line_request.json | jq .10. Send Template Message (Buttons)
10. 发送模板消息(按钮)
Send a button template message with actions.
Write to :
/tmp/line_request.jsonjson
{
"to": "USER_ID",
"messages": [
{
"type": "template",
"altText": "Button template",
"template": {
"type": "buttons",
"title": "Menu",
"text": "Please select an option",
"actions": [
{
"type": "message",
"label": "Option 1",
"text": "option1"
},
{
"type": "uri",
"label": "Visit Website",
"uri": "https://example.com"
}
]
}
}
]
}Then run:
bash
curl -s -X POST "https://api.line.me/v2/bot/message/push" --header "Content-Type: application/json" --header "Authorization: Bearer $LINE_TOKEN" -d @/tmp/line_request.json | jq .发送带有操作的按钮模板消息。
写入:
/tmp/line_request.jsonjson
{
"to": "USER_ID",
"messages": [
{
"type": "template",
"altText": "Button template",
"template": {
"type": "buttons",
"title": "Menu",
"text": "Please select an option",
"actions": [
{
"type": "message",
"label": "Option 1",
"text": "option1"
},
{
"type": "uri",
"label": "Visit Website",
"uri": "https://example.com"
}
]
}
}
]
}然后运行:
bash
curl -s -X POST "https://api.line.me/v2/bot/message/push" --header "Content-Type: application/json" --header "Authorization: Bearer $LINE_TOKEN" -d @/tmp/line_request.json | jq .11. Get Webhook Endpoint
11. 获取Webhook端点
Retrieve the current webhook URL configuration.
bash
curl -s "https://api.line.me/v2/bot/channel/webhook/endpoint" --header "Authorization: Bearer $LINE_TOKEN" | jq .获取当前Webhook URL配置。
bash
curl -s "https://api.line.me/v2/bot/channel/webhook/endpoint" --header "Authorization: Bearer $LINE_TOKEN" | jq .12. Set Webhook Endpoint
12. 设置Webhook端点
Configure the webhook URL where LINE sends events.
bash
curl -s -X PUT "https://api.line.me/v2/bot/channel/webhook/endpoint" --header "Content-Type: application/json" --header "Authorization: Bearer $LINE_TOKEN" -d '{"endpoint":"https://example.com/webhook"}' | jq .配置LINE发送事件的Webhook URL。
bash
curl -s -X PUT "https://api.line.me/v2/bot/channel/webhook/endpoint" --header "Content-Type: application/json" --header "Authorization: Bearer $LINE_TOKEN" -d '{"endpoint":"https://example.com/webhook"}' | jq .13. Test Webhook
13. 测试Webhook
Test the webhook endpoint connectivity.
bash
curl -s -X POST "https://api.line.me/v2/bot/channel/webhook/test" --header "Content-Type: application/json" --header "Authorization: Bearer $LINE_TOKEN" -d '{"endpoint":"https://example.com/webhook"}' | jq .测试Webhook端点的连通性。
bash
curl -s -X POST "https://api.line.me/v2/bot/channel/webhook/test" --header "Content-Type: application/json" --header "Authorization: Bearer $LINE_TOKEN" -d '{"endpoint":"https://example.com/webhook"}' | jq .14. List Rich Menus
14. 列出富菜单
Get all rich menus created for the bot.
bash
curl -s "https://api.line.me/v2/bot/richmenu/list" --header "Authorization: Bearer $LINE_TOKEN" | jq '.richmenus[] | {richMenuId, name, size}'获取为机器人创建的所有富菜单。
bash
curl -s "https://api.line.me/v2/bot/richmenu/list" --header "Authorization: Bearer $LINE_TOKEN" | jq '.richmenus[] | {richMenuId, name, size}'15. Create Rich Menu
15. 创建富菜单
Create a new rich menu.
Write to :
/tmp/line_request.jsonjson
{
"size": {
"width": 2500,
"height": 1686
},
"selected": false,
"name": "Main Menu",
"chatBarText": "Menu",
"areas": [
{
"bounds": {
"x": 0,
"y": 0,
"width": 1250,
"height": 1686
},
"action": {
"type": "message",
"text": "Left button tapped"
}
},
{
"bounds": {
"x": 1250,
"y": 0,
"width": 1250,
"height": 1686
},
"action": {
"type": "message",
"text": "Right button tapped"
}
}
]
}Then run:
bash
curl -s -X POST "https://api.line.me/v2/bot/richmenu" --header "Content-Type: application/json" --header "Authorization: Bearer $LINE_TOKEN" -d @/tmp/line_request.json | jq .创建新的富菜单。
写入:
/tmp/line_request.jsonjson
{
"size": {
"width": 2500,
"height": 1686
},
"selected": false,
"name": "Main Menu",
"chatBarText": "Menu",
"areas": [
{
"bounds": {
"x": 0,
"y": 0,
"width": 1250,
"height": 1686
},
"action": {
"type": "message",
"text": "Left button tapped"
}
},
{
"bounds": {
"x": 1250,
"y": 0,
"width": 1250,
"height": 1686
},
"action": {
"type": "message",
"text": "Right button tapped"
}
}
]
}然后运行:
bash
curl -s -X POST "https://api.line.me/v2/bot/richmenu" --header "Content-Type: application/json" --header "Authorization: Bearer $LINE_TOKEN" -d @/tmp/line_request.json | jq .16. Delete Rich Menu
16. 删除富菜单
Delete a rich menu by ID.
bash
curl -s -X DELETE "https://api.line.me/v2/bot/richmenu/RICH_MENU_ID" --header "Authorization: Bearer $LINE_TOKEN" | jq .通过ID删除富菜单。
bash
curl -s -X DELETE "https://api.line.me/v2/bot/richmenu/RICH_MENU_ID" --header "Authorization: Bearer $LINE_TOKEN" | jq .17. Get Message Delivery Statistics
17. 获取消息送达统计
Get the number of messages delivered on a specific date (format: ).
yyyyMMddbash
curl -s "https://api.line.me/v2/bot/insight/message/delivery?date=20260301" --header "Authorization: Bearer $LINE_TOKEN" | jq .获取特定日期(格式:)的消息送达数量。
yyyyMMddbash
curl -s "https://api.line.me/v2/bot/insight/message/delivery?date=20260301" --header "Authorization: Bearer $LINE_TOKEN" | jq .18. Get Follower Demographics
18. 获取关注者人口统计数据
Retrieve demographic data about followers (gender, age, area distribution).
bash
curl -s "https://api.line.me/v2/bot/insight/demographic" --header "Authorization: Bearer $LINE_TOKEN" | jq .获取关注者的人口统计数据(性别、年龄、地区分布)。
bash
curl -s "https://api.line.me/v2/bot/insight/demographic" --header "Authorization: Bearer $LINE_TOKEN" | jq .19. Get Group Summary
19. 获取群组摘要
Retrieve information about a group chat the bot is a member of.
bash
curl -s "https://api.line.me/v2/bot/group/GROUP_ID/summary" --header "Authorization: Bearer $LINE_TOKEN" | jq .获取机器人所在群组的信息。
bash
curl -s "https://api.line.me/v2/bot/group/GROUP_ID/summary" --header "Authorization: Bearer $LINE_TOKEN" | jq .20. Get Group Member Profile
20. 获取群组成员资料
Retrieve the profile of a specific member in a group chat.
bash
curl -s "https://api.line.me/v2/bot/group/GROUP_ID/member/USER_ID" --header "Authorization: Bearer $LINE_TOKEN" | jq .获取群组中特定成员的资料。
bash
curl -s "https://api.line.me/v2/bot/group/GROUP_ID/member/USER_ID" --header "Authorization: Bearer $LINE_TOKEN" | jq .Message Types
消息类型
LINE supports multiple message types in the array:
messages| Type | Description |
|---|---|
| Plain text message |
| Image with original and preview URLs |
| Video with original and preview URLs |
| Audio file with duration |
| Location with title, address, and coordinates |
| LINE sticker with package and sticker IDs |
| Interactive template (buttons, confirm, carousel) |
| Flexible layout message using Flex Message JSON |
LINE在数组中支持多种消息类型:
messages| Type | Description |
|---|---|
| 纯文本消息 |
| 包含原图和预览图URL的图片 |
| 包含原视频和预览图URL的视频 |
| 包含时长的音频文件 |
| 包含标题、地址和坐标的位置信息 |
| 包含包ID和贴纸ID的LINE贴纸 |
| 交互式模板(按钮、确认、轮播) |
| 使用Flex Message JSON的灵活布局消息 |
Guidelines
注意事项
- Message limits: Push messages count toward your monthly quota. Free plans have limited push messages. Reply messages are free
- Reply tokens: Reply tokens from webhook events expire quickly. Process and reply promptly
- Multicast limit: Multicast supports up to 500 user IDs per request
- Rich menu images: After creating a rich menu, upload an image separately using the content upload endpoint
- User IDs: User IDs are channel-specific. The same user has different IDs across different channels
- Message objects: Each request can contain up to 5 message objects in the array
messages - HTTPS required: All image, video, and audio URLs must use HTTPS
- Webhook verification: LINE sends a signature in the header for webhook verification using HMAC-SHA256
x-line-signature
- 消息限制:推送消息会计入您的月度配额。免费套餐的推送消息数量有限。回复消息免费
- 回复令牌:来自Webhook事件的回复令牌过期很快,请及时处理并回复
- 群发限制:群发请求最多支持500个用户ID
- 富菜单图片:创建富菜单后,需使用内容上传端点单独上传图片
- 用户ID:用户ID是频道专属的。同一用户在不同频道拥有不同的ID
- 消息对象:每个请求的数组中最多可包含5个消息对象
messages - 要求HTTPS:所有图片、视频和音频URL必须使用HTTPS
- Webhook验证:LINE会在头中发送签名,用于使用HMAC-SHA256进行Webhook验证
x-line-signature