This document describes how to integrate Kakao Talk Sharing APIs into your service with the Kakao SDK for Flutter ("Flutter SDK").
To use the Kakao Talk Sharing API on the native app service, you must set the Custom URL Scheme. See how to set up a project by device environment below.
In Flutter SDK 1.2.0, the names of the module, classes, and methods related to Kakao Talk Sharing have been changed due to the change of its service name. To see more detailed changes, see Version history.
According to your service's purpose and requirements, you need to decide which API to use first by considering their characteristics and difference.
1. Select a type of Messaging APIThere are two types of messaging APIs: the Kakao Talk Sharing API and the Kakao Talk Messaging API. You need to understand the differences between the two messaging APIs completely by referring to Concepts, and decide which API to use to implement the function to send a message.
Decide which message template to use by referring to Message template > Types.
You can configure a message according to the default template in JSON format or create a custom template in person for your service. Refer to How to use for more details.
After configuring a message, you must call the corresponding API according to the desired message template type. If the request is successful, the Flutter SDK launches Kakao Talk or lets a user log in with Kakao Account on a web page, and then shows a list of friends or chatrooms. When a user selects friends or a chatroom to send the message to, the messages are sent to the selected targets.
To figure out if it is possible to share a message through Kakao Talk, you can use the isKakaoTalkSharingAvailable()
method.
Depending on the return value of isKakaoTalkSharingAvailable()
, you need to handle the outcome differently by either sharing via Kakao Talk or sharing via web.
Return value | How to handle |
---|---|
true |
Share messages through Kakao Talk installed on a user's mobile device. Refer to the 'Sharing via Kakao Talk' column in APIs by conditions. NOTE: If a web app is running on Android or iOS, isKakaoTalkSharingAvailable() returns true regardless of whether Kakao Talk is installed. Thus, true does not guarantee that Kakao Talk is installed on the user's Android or iOS device. |
false |
If Kakao Talk is not available, share messages through a web view as follows: 1. Create a sharable URL by calling the method described in the 'Sharing via web' column in APIs by conditions. 2. Call the launchBrowserTab() method with the returned URL to open the URL via a web view or a default browser. To open the URL as a pop-up window in your web app, pass popupOpen as an argument and set it to true . Note that popupOpen works only in a web app; however, some web views may not allow the pop-up window to appear normally.NOTE: If a web app is running on environments other than Android and iOS, isKakaoTalkSharingAvailable() returns false regardless of whether Kakao Talk is installed. |
According to the desired message type, user environments, the methods to use are different. Here are the methods to call by message type and configuration method:
Message type | Configuration method | Sharing via Kakao Talk | Sharing via web |
---|---|---|---|
Feed, List, Location, Commerce, Text, Calendar | Default template | shareDefault() |
makeDefaultUrl() |
Feed, List, Commerce | Custom template | shareCustom() |
makeCustomUrl() |
Scrape | Default template | shareScrap() |
makeScrapUrl() |
Scrape | Custom template | shareScrap() |
makeScrapUrl() |
When you configure a Kakao Talk message through the Kakao Talk Sharing or Kakao Talk Messaging APIs, use one of the classes defined in DefaultTemplate
according to a message type by referring to Message template components. Then, create an object for the desired message type among five types, and define the message content for the template object.
Here are the code snippets showing how to configure a message for each message type.
final FeedTemplate defaultFeed = FeedTemplate(
content: Content(
title: 'Strawberry Cheese Cake',
description: '#Cake #Strawberry #Sampyeong-dong #Cafe #Vibe #BlindDate',
imageUrl: Uri.parse(
'https://mud-kage.kakao.com/dn/Q2iNx/btqgeRgV54P/VLdBs9cvyn8BJXB3o7N8UK/kakaolink40_original.png'),
link: Link(
webUrl: Uri.parse('https://developers.kakao.com'),
mobileWebUrl: Uri.parse('https://developers.kakao.com')),
),
itemContent: ItemContent(
profileText: 'Kakao',
profileImageUrl: Uri.parse(
'https://mud-kage.kakao.com/dn/Q2iNx/btqgeRgV54P/VLdBs9cvyn8BJXB3o7N8UK/kakaolink40_original.png'),
titleImageUrl: Uri.parse(
'https://mud-kage.kakao.com/dn/Q2iNx/btqgeRgV54P/VLdBs9cvyn8BJXB3o7N8UK/kakaolink40_original.png'),
titleImageText: 'Cheese cake',
titleImageCategory: 'cake',
items: [
ItemInfo(item: 'cake1', itemOp: '1000 won'),
ItemInfo(item: 'cake2', itemOp: '2000 won'),
ItemInfo(item: 'cake3', itemOp: '3000 won'),
ItemInfo(item: 'cake4', itemOp: '4000 won'),
ItemInfo(item: 'cake5', itemOp: '5000 won')
],
sum: 'total',
sumOp: '15000 won',
),
social: Social(likeCount: 286, commentCount: 45, sharedCount: 845),
buttons: [
Button(
title: 'View on Web',
link: Link(
webUrl: Uri.parse('https: //developers.kakao.com'),
mobileWebUrl: Uri.parse('https: //developers.kakao.com'),
),
),
Button(
title: 'View on App',
link: Link(
androidExecutionParams: {'key1': 'value1', 'key2': 'value2'},
iosExecutionParams: {'key1': 'value1', 'key2': 'value2'},
),
),
],
);
final ListTemplate defaultList = ListTemplate(
headerTitle: 'WEEKLY MAGAZINE',
headerLink: Link(
webUrl: Uri.parse('https://developers.kakao.com'),
mobileWebUrl: Uri.parse('https://developers.kakao.com'),
),
contents: [
Content(
title: 'My hobby, Table tennis',
description: 'Sports',
imageUrl: Uri.parse(
'https://mud-kage.kakao.com/dn/bDPMIb/btqgeoTRQvd/49BuF1gNo6UXkdbKecx600/kakaolink40_original.png'),
link: Link(
webUrl: Uri.parse('https://developers.kakao.com'),
mobileWebUrl: Uri.parse('https://developers.kakao.com'),
),
),
Content(
title: 'Understanding coffee with cream',
description: 'Food',
imageUrl: Uri.parse(
'https://mud-kage.kakao.com/dn/QPeNt/btqgeSfSsCR/0QJIRuWTtkg4cYc57n8H80/kakaolink40_original.png'),
link: Link(
webUrl: Uri.parse('https://developers.kakao.com'),
mobileWebUrl: Uri.parse('https://developers.kakao.com'),
),
),
Content(
title: 'Emotional atmosphere',
description: 'Photo',
imageUrl: Uri.parse(
'https://mud-kage.kakao.com/dn/c7MBX4/btqgeRgWhBy/ZMLnndJFAqyUAnqu4sQHS0/kakaolink40_original.png'),
link: Link(
webUrl: Uri.parse('https://developers.kakao.com'),
mobileWebUrl: Uri.parse('https://developers.kakao.com'),
),
),
],
buttons: [
Button(
title: 'View on Web',
link: Link(
webUrl: Uri.parse('https://developers.kakao.com'),
mobileWebUrl: Uri.parse('https://developers.kakao.com'),
),
),
Button(
title: 'View on App',
link: Link(
androidExecutionParams: {'key1': 'value1', 'key2': 'value2'},
iosExecutionParams: {'key1': 'value1', 'key2': 'value2'},
),
),
],
);
final LocationTemplate defaultLocation = LocationTemplate(
address: '235, Pangyoyeok-ro, Bundang-gu, Seongnam-si, Gyeonggi-do',
content: Content(
title: '"New menu release❤️ Cherry Blossom Latte',
description: 'Cherry blossom latte 1+1 for this week',
imageUrl: Uri.parse(
'https://mud-kage.kakao.com/dn/bSbH9w/btqgegaEDfW/vD9KKV0hEintg6bZT4v4WK/kakaolink40_original.png'),
link: Link(
webUrl: Uri.parse('https://developers.kakao.com'),
mobileWebUrl: Uri.parse('https://developers.kakao.com'),
),
),
social: Social(likeCount: 286, commentCount: 45, sharedCount: 845),
);
final CommerceTemplate defaultCommerce = CommerceTemplate(
content: Content(
title: 'Ivory long dress (4 Color)',
imageUrl: Uri.parse(
'https://mud-kage.kakao.com/dn/RY8ZN/btqgOGzITp3/uCM1x2xu7GNfr7NS9QvEs0/kakaolink40_original.png'),
link: Link(
webUrl: Uri.parse('https://developers.kakao.com'),
mobileWebUrl: Uri.parse('https://developers.kakao.com'),
),
),
commerce: Commerce(
regularPrice: 208800,
discountPrice: 146160,
discountRate: 30,
productName: "Ivory long dress",
currencyUnit: "₩",
currencyUnitPosition: 1,
),
buttons: [
Button(
title: 'Purchase',
link: Link(
webUrl: Uri.parse('https://developers.kakao.com'),
mobileWebUrl: Uri.parse('https://developers.kakao.com'),
),
),
Button(
title: 'Share',
link: Link(
androidExecutionParams: {'key1': 'value1', 'key2': 'value2'},
iosExecutionParams: {'key1': 'value1', 'key2': 'value2'},
),
)
],
);
final TextTemplate defaultText = TextTemplate(
text:
'The Text template provided as a default template can contain text up to 200 characters. The Text template has a text area and a default button. You can also add an additional button. If you use Kakao Talk Sharing, you can send a message with a more extended form of templates, such as sending multiple images and profile information.',
link: Link(
webUrl: Uri.parse('https: //developers.kakao.com'),
mobileWebUrl: Uri.parse('https: //developers.kakao.com'),
),
);
final CalendarTemplate defaultCalendar = CalendarTemplate(
idType: IdType.event,
id: '${YOUR_EVENT_ID}',
content: Content(
title: 'Fashion show for S/S collection',
description: 'Join this upcoming event! To add this event to your calendar, click [일정 등록 하기].',
imageUrl: Uri.parse(
'https://mud-kage.kakao.com/dn/RY8ZN/btqgOGzITp3/uCM1x2xu7GNfr7NS9QvEs0/kakaolink40_original.png'),
link: Link(
webUrl: Uri.parse('https://developers.kakao.com'),
mobileWebUrl: Uri.parse('https://developers.kakao.com'),
),
),
buttons: [
Button(
title: 'Purchase',
link: Link(
webUrl: Uri.parse('https://developers.kakao.com'),
mobileWebUrl: Uri.parse('https://developers.kakao.com'),
),
)
],
);
As an example, here are the steps to configure and send a Feed message.
1. Figure out template componentsCheck which object you should create for a Feed message by referring to Message template > Feed message. Feed message is defined as the FeedTemplate class.
Create the FeedTemplate
object by referring to the guide and reference. As you check in Step 1, the Feed message contains content
, social
, buttons
, buttonTitle
, and itemContent
components. You must declare the required component, content
for Feed message, in the object.
Pass the FeedTemplate
object created in Step 2 when calling the Kakao Talk Sharing or Kakao Talk Messaging API.
Reference | App setting |
---|---|
shareDefault() makeDefaultUrl() SharingResult |
Install Initialize |
Permission | Prerequisite | Kakao Login | User consent |
---|---|---|---|
- | Register platforms | - | - |
You can configure a Kakao Talk message in your source code using a default template, and then share the message with others. The default templates are defined in the DefaultTemplate
class.
To share the configured message through Kakao Talk, call the shareDefault()
method.
For a device where Kakao Talk Sharing is not available, share the message via the web by calling the makeDefaultUrl()
and launchBrowserTab
methods. For more details, refer to Decide implementation method.
Calling shareDefault()
launches the Kakao Talk application and shows the list of user's Kakao Talk friends or chatrooms. When a user selects friends or a chatroom to send the message to, the messages are sent to the selected targets.
shareDefault()
returns SharingResult
. Because the Kakao Talk Sharing API does not inform the result of message delivery, implement the Kakao Talk Sharing success callback function.
// Check if Kakao Talk is installed.
bool result = await ShareClient.instance.isKakaoTalkSharingAvailable();
if (result) {
print('Kakao Talk Sharing is available.');
} else {
print('If Kakao Talk is not installed, we recommend Kakao Talk Sharing via web.');
}
// Send a Feed message.
try {
Uri uri = await ShareClient.instance.shareDefault(template: defaultFeed);
await ShareClient.instance.launchKakaoTalk(uri);
print('Succeeded in Kakao Talk Sharing.');
} catch (error) {
print('Kakao Talk Sharing failed. $error');
}
Reference | App setting |
---|---|
shareCustom() makeCustomUrl() SharingResult |
Install Initialize |
Permission | Prerequisite | Kakao Login | User consent |
---|---|---|---|
- | Register platforms Message Template |
- | - |
You can customize a template for Kakao Talk messages in [Tools] > [Message Template Builder], and then share the message with the customized template with others. To see how to configure a custom template, refer to Message template builder.
To share the configured message through Kakao Talk, call the shareCustom()
method.
For a device where Kakao Talk Sharing is not available, share the message via the web by calling the makeCustomUrl()
and launchBrowserTab
methods. For more details, refer to Decide implementation method.
Calling shareCustom()
launches the Kakao Talk application and shows the list of user's Kakao Talk friends or chatrooms. When a user selects friends or a chatroom to send the message to, the messages are sent to the selected targets.
shareCustom()
returns SharingResult
. Because the Kakao Talk Sharing API does not inform the result of message delivery, implement the Kakao Talk Sharing success callback function.
// Sending Kakao Talk Sharing message using custom template.
// * Refer to the guide: https://developers.kakao.com/docs/latest/en/message/message-templatee/message-template
// Template ID
int templateId = templateIds['customMemo']!;
// Check if Kakao Talk is installed.
bool result = await ShareClient.instance.isKakaoTalkSharingAvailable();
// If Kakao Talk is installed, the Kakao Talk Sharing message is sent through Kakao Talk.
if (result) {
try {
Uri uri = await ShareClient.instance.shareCustom(templateId: templateId, templateArgs: {'key1': 'value1'});
await ShareClient.instance.launchKakaoTalk(uri);
print('Succeeded in Kakao Talk Sharing.');
} catch (error) {
print('Kakao Talk Sharing failed. $error');
}
} else {
// If Kakao Talk is not installed, we recommend sending the Kakao Talk Sharing message via web.
int templateId = templateIds['customMemo']!;
try {
Uri shareUrl = await WebSharerClient.instance.makeCustomUrl(
templateId: templateId, templateArgs: {'key1': 'value1'});
await launchBrowserTab(shareUrl, popupOpen: true);
} catch (error) {
print('Kakao Talk Sharing failed. $error');
}
}
Reference | App setting |
---|---|
shareScrap() makeScrapUrl() SharingResult |
Install Initialize |
Permission | Prerequisite | Kakao Login | User consent |
---|---|---|---|
- | Register platforms | - | - |
You can scrape a web page with a default template, and then share the scraped message with others.
To share the scraped message through Kakao Talk, call the shareScrap()
method.
For a device where Kakao Talk Sharing is not available, share the message via the web by calling the makeScrapUrl()
and launchBrowserTab
methods. For more details, refer to Decide implementation method.
Calling shareScrap()
launches the Kakao Talk application and shows the list of user's Kakao Talk friends or chatrooms. When a user selects friends or a chatroom to send the message to, the messages are sent to the selected targets.
shareScrap()
returns SharingResult
. Because the Kakao Talk Sharing API does not inform the result of message delivery, implement the Kakao Talk Sharing success callback function.
// Sending Kakao Talk Sharing message using default template.
// Check if Kakao Talk is installed.
bool result = await ShareClient.instance.isKakaoTalkSharingAvailable();
// If Kakao Talk is installed, the Kakao Talk Sharing message is sent through Kakao Talk.
if (result) {
// Web page URL to be shared.
// * CAUTION: The domain of the URL to be shared must be registered in [My Appliction] > [Platform] > [Web] in Kakao Developers.
String url = "https://developers.kakao.com";
try {
Uri uri = await ShareClient.instance.shareScrap(url: url);
await ShareClient.instance.launchKakaoTalk(uri);
print('Succeeded in Kakao Talk Sharing.');
} catch (error) {
print('Kakao Talk Sharing failed. $error');
}
} else {
// If Kakao Talk is not installed, we recommend sending the Kakao Talk Sharing message via web.
String url = "https://developers.kakao.com";
try {
Uri shareUrl = await WebSharerClient.instance.makeScrapUrl(url: url);
await launchBrowserTab(shareUrl, popupOpen: true);
} catch (error) {
print('Kakao Talk Sharing failed. $error');
}
}
Reference | App setting |
---|---|
shareScrap() makeScrapUrl() SharingResult |
Install Initialize |
Permission | Prerequisite | Kakao Login | User consent |
---|---|---|---|
- | Register platforms Message Template |
- | - |
You can scrape a web page and then share the scraped message with a custom template congfigured in [Tools] > [Message Template Builder]. To see how to configure a custom template, refer to Message template builder.
To share the scraped message through Kakao Talk, call the shareScrap()
method.
For a device where Kakao Talk Sharing is not available, share the message via the web by calling the makeScrapUrl()
and launchBrowserTab
methods. For more details, refer to Decide implementation method.
Calling shareScrap()
launches the Kakao Talk application and shows the list of user's Kakao Talk friends or chatrooms. When a user selects friends or a chatroom to send the message to, the messages are sent to the selected targets.
shareScrap()
returns SharingResult
. Because the Kakao Talk Sharing API does not inform the result of message delivery, implement the Kakao Talk Sharing success callback function.
// Sending Kakao Talk Sharing message using custom template.
// Check if Kakao Talk is installed.
bool result = await ShareClient.instance.isKakaoTalkSharingAvailable();
// Web page URL to be shared.
// * CAUTION: The domain of the URL to be shared must be registered in [My Appliction] > [Platform] > [Web] in Kakao Developers.
String url = "https://developers.kakao.com";
// Template ID
int templateId = templateIds['customMemo']!;
// If Kakao Talk is installed, the Kakao Talk Sharing message is sent through Kakao Talk.
if (result) {
try {
Uri uri = await ShareClient.instance.shareScrap(url: url, templateId: templateId, templateArgs: {'key1': 'value1'});
await ShareClient.instance.launchKakaoTalk(uri);
print('Succeeded in Kakao Talk Sharing.');
} catch (error) {
print('Kakao Talk Sharing failed. $error');
}
} else {
// If Kakao Talk is not installed, we recommend sending the Kakao Talk Sharing message via web.
try {
Uri shareUrl = await WebSharerClient.instance.makeScrapUrl(url: url, templateId: templateId, templateArgs: {'key1': 'value1'});
await launchBrowserTab(shareUrl, popupOpen: true);
} catch (error) {
print('Kakao Talk Sharing failed. $error');
}
}
The Kakao Talk Sharing success callback is a function to send a callback request to the URL specified on Kakao Developers when a Kakao Talk Sharing message is successfully sent to friends or a chatroom selected by a user. This function is only available for Kakao Talk Sharing API, not for Kakao Talk Messaging API.
To use this feature, you need to:
serverCallbackArgs
to pass additional information when requesting the Kakao Talk Sharing API.To use the Kakao Talk Sharing success callback function, you must specify a custom parameter through serverCallbackArgs
. Otherwise, you cannot receive Kakao Talk Sharing success callbacks even though you registered a callback URL for Kakao Talk Sharing in [My Application]. When your service server receives a Kakao Talk Sharing success callback, you can figure out additional information through the predefined custom parameters, such as what content the user has shared.
To pass additional information when requesting the Kakao Talk Sharing API, declare serverCallbackArgs
, and pass keys and values as a Map. You cannot use the system reserved words CHAT_TYPE
, HASH_CHAT_ID
and TEMPLATE_ID
as keys for the serverCallbackArgs
. The key is included in the notification with the value defined in the specification of Kakao Talk Sharing success callback.
Here is a code snippet showing how to set parameters for Kakao Talk Sharing success callback.
int templateId = templateIds['customMemo']!;
Map<String, String> serverCallbackArgs = ["userId": "abcd", "productId": "1234"]
// Checking if Kakao Talk is installed.
bool result = await ShareClient.instance.isKakaoTalkSharingAvailable();
// If Kakao Talk is installed, the Kakao Talk Sharing message is sent through Kakao Talk.
if (result) {
try {
Uri uri = await ShareClient.instance.shareCustom(templateId: templateId, serverCallbackArgs: serverCallbackArgs);
await ShareClient.instance.launchKakaoTalk(uri);
print('Succeeded in Kakao Talk Sharing.');
} catch (error) {
print('Kakao Talk Sharing failed. $error');
} else {
// If Kakao Talk is not installed, we recommend sending the Kakao Talk Sharing message via web.
try {
Uri shareUrl = await WebSharerClient.instance.makeCustomUrl(templateId: templateId, serverCallbackArgs: serverCallbackArgs);
await launchBrowserTab(shareUrl, popupOpen: true);
} catch (error) {
print('Kakao Talk Sharing failed. $error');
}
}
If the Kakao Talk Sharing message is successfully sent, Kakao sends a Kakao Talk Sharing success callback including the specified parameters to the callback URL of your service server. For more information on the callback request, refer to Reference Information > Kakao Talk Sharing success callback.
Reference | App setting |
---|---|
uploadImage() scrapImage() ImageUploadResult ImageInfo |
Install Initialize |
Permission | Prerequisite | Kakao Login | User consent |
---|---|---|---|
- | Register platforms | - | - |
You can attach images to a Kakao Talk message by passing an image URL when configuring a message template or uploading images in the Message template builder in advance.
If it is difficult to obtain the image file URL, you can either upload an image file to the Kakao server or scrape it. You can only upload an image with a file size of 5 MB or less. The images uploaded to the Kakao server are stored for up to 100 days and automatically deleted after the period.
To upload an image on the Android or iOS platforms, call the uploadImage()
method defined in the ShareClient
class. To upload an image on a web platform, call the uploadImage()
method defined in the WebSharerClient
class.
You can only upload an image with a file size of 5 MB or less by passing image
or byteData
.
To use an image by scraping an image uploaded on the web page, call the scrapImage()
method defined in the ShareClient
class.
When the request is successful, the information of the uploaded image is returned through the ImageUploadResult
class.
// Uploading image
// Image file to be uploaded. In this sample, the image file added as a project resource is used.
ByteData byteData = await rootBundle.load('assets/images/cat1.png');
// In this sample, the project resource is saved as an image file by using path_provider.
File tempFile =
File('${(await getTemporaryDirectory()).path}/cat1.png');
File file = await tempFile.writeAsBytes(byteData.buffer
.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));
try {
// Uploading an image to the Kakao image server
ImageUploadResult imageUploadResult =
await ShareClient.instance.uploadImage(image: file);
print('Succeeded in uploading an image. \n${imageUploadResult.infos.original}');
} catch (error) {
print('Failed to upload an image. $error');
}
// Uploading image
// In this code snippet, file_picker is used to load images.
var filePickerResult = await FilePicker.platform.pickFiles();
if (filePickerResult != null) {
var byteData = filePickerResult.files.first.bytes;
try {
// Uploading an image to the Kakao image server
ImageUploadResult imageUploadResult =
await WebSharerClient.instance.uploadImage(byteData: byteData);
print('Succeeded in uploading an image. \n${imageUploadResult.infos.original}');
} catch (eror) {
print('Failed to upload an image. $error');
}
}
// Scraping an image
// URL of the original image.
String url =
'http://k.kakaocdn.net/dn/Q2iNx/btqgeRgV54P/VLdBs9cvyn8BJXB3o7N8UK/kakaolink40_original.png';
try {
// Uploading an image to the Kakao image server
ImageUploadResult imageUploadResult =
await ShareClient.instance.scrapImage(imageUrl: url);
print('Succeeded in scraping an image.\n${imageUploadResult.infos.original}');
} catch (error) {
print('Failed to scrape an image. $error');
}