# Add a LINE Official Account as a friend when logged in (bot link)
You can display an option to add the LINE Official Account as a friend when a user logs in to your app. This is called the bot link feature. Specify the LINE Official Account to be added as a friend on the LINE Developers Console.
If the user enables Add friend on the above consent screen when logging in, the LINE Official Account will be added as a friend. For more information on creating bots, see Messaging API overview in the Messaging API documentation.
# Displaying the option to add your LINE Official Account as a friend
To display the option to add your LINE Official Account as a friend on the consent screen, configure the settings as below.
- Link a LINE Official Account with your channel
- Redirect users to the LINE Login authorization URL with the
bot_prompt
query parameter
# Link a LINE Official Account with your channel
Link a LINE Official Account with your LINE Login channel on the LINE Developers Console.
These conditions must be met for you to link a LINE Official Account to your LINE Login channel.
- The Messaging API channel associated with the LINE Official Account belongs to the same provider as your LINE Login channel.
- You are an administrator of both the LINE Login channel and the LINE Official Account.
- You can review the administrator privileges for a LINE Login channel with the LINE Developers Console.
- You can review the administrator privileges for a LINE Official Account with the LINE Official Account Manager (opens new window).
Log in to the LINE Developers Console and click the provider that contains the channel for LINE Login.
Open your LINE Login channel settings.
On the Basic settings tab, under Linked OA, click Edit.
Select the LINE Official Account you want users to add and click Update.
You can select a LINE Official Account for which you have an administrator role.
You can link only one LINE Official Account to a LINE Login channel.
# Redirect users to the LINE Login authorization URL with the bot_prompt
query parameter
Redirect users to the LINE Login authorization URL with the bot_prompt
query parameter as shown below.
https://access.line.me/oauth2/v2.1/authorize?response_type=code&client_id={CHANNEL_ID}&redirect_uri={CALLBACK_URL}&state={STATE}&bot_prompt={BOT_PROMPT}&scope={SCOPE_LIST}
These options are displayed depending on the bot_prompt
query parameter.
Value | Description |
---|---|
normal | Display the option to add a LINE Official Account as a friend in the consent screen. |
aggressive | Opens a new screen with an option to add the LINE Official Account as a friend after the consent screen. |
For more information on query parameters other than bot_prompt
, see Making an authorization request.
# Display options on the consent screen
The option to add a LINE Official Account as a friend is displayed as follows according to the relationship between the user and the LINE Official Account.
Friend relationship when consent screen is displayed | Options shown to the user |
---|---|
Not a friend | Displays the option to add a LINE Official Account as a friend. The LINE Official Account is added as a friend if the user selects the option and continues. |
Blocked | Displays the option to unblock the LINE Official Account. The LINE Official Account is unblocked if the user selects the option and continues. |
Added as friend | Shows that the user has added the LINE Official Account as a friend. No option is displayed to add the LINE Official Account as a friend. |
# Getting the friendship status of the user and the LINE Official Account
When using bot links, you can get the friendship status between a user and the LINE Official Account linked to your LINE Login channel through one of these methods.
- Use the
friendship_status_changed
query parameter - Use the LINE Login API to determine the friendship status
# Use the friendship_status_changed
query parameter
If you specify the bot_prompt
query parameter when you make an authorization request, the user is redirected to the callback URL with the friendship_status_changed
query parameter once they have been authenticated and have authorized your app.
Example URL of the redirect target:
https://client.example.org/cb?code={CODE}&state={STATE}&friendship_status_changed={FRIENDSHIP_STATUS_CHANGED}
The friendship_status_changed
query parameter can take the following values. For more information on the callback URL, see Receiving the authorization code.
Value | Description |
---|---|
true | The friendship status of the user and the LINE Official Account changed during login. This occurs in one of these situations:
|
false | The friendship status of the user and the LINE Official Account didn't change during login. This occurs in one of these situations:
|
friendship_status_changed
query parameter isn't included if the consent screen with the option to add your LINE Official Account as a friend isn't displayed to the user.
# Use the LINE Login API to get the friendship status
You can use the access token retrieved by your web app to get the friendship status between a user and the LINE Official Account linked to your LINE Login channel.
Example request:
curl -v -X GET https://api.line.me/friendship/v1/status \
-H 'Authorization: Bearer {access token}'
Example response:
{
"friendFlag": true
}
To learn more, see Getting the friendship status of the user and the LINE Official Account in the LINE Login v2.1 API reference.