페이지 이동경로
  • Docs>
  • Kakao Story>
  • Flutter

Kakao Story

Flutter

This document describes how to integrate Kakao Story APIs into your service with the Kakao SDK for Flutter (hereinafter referred to as 'Flutter SDK').

Before you begin

Before using Kakao Story APIs with the Flutter SDK,

  1. Complete the prerequisites.
  2. Implement Kakao Login to call the token-based APIs. To obtain the tokens, a user also must be logged in with Kakao. For more information, refer to Concepts > Kakao Login.
  3. After adding kakao_flutter_sdk_story and kakao_flutter_sdk_user in pubspec.yaml by referring to Install SDK, import the corresponding libraries in your dart file.

Project Setting

To launch the service app by story link on the native app service, you must set the Custom URL Scheme. See how to set up a project by device environment below.

Validate Kakao Story user

Basic information
Permission Prerequisite Kakao Login User consent
- Register platforms
Activate Kakao Login
Manage consent items
Required -

To check if the user who is currently logged in is using Kakao Story, call the isStoryUser() method in the StoryApi class.

Sample
// Checking if user is using Kakao Story
try {
  bool isStoryUser = await StoryApi.instance.isStoryUser();
  print('Whether to use Kakao Story: $isStoryUser');
} catch (error) {
  print('Failed to validate Kakao Story user registration. $error');
}

isStoryUser() returns true if the user is using Kakao Story. If the user is not using Kakao Story, false is returned so that you can take action to prevent an error that occurs when calling Kakao Story APIs for the user.

Retrieve Kakao Story profile

Basic information
Permission Prerequisite Kakao Login User consent
- Register platforms
Activate Kakao Login
Manage consent items
Required Required:
Profile Info(nickname/profile image)
Nickname
Profile image
KakaoStory Profile URL

To retrieve the Kakao Story profile information of the user who is currently logged in, call the profile() method in the StoryApi class.

Sample
// Retrieving Kakao Story profile
try {
  StoryProfile profile = await StoryApi.instance.profile();
  print('Succeeded in retrieving Kakao Story profile. \nNickname: ${profile.nickname}\nProfile Image: ${profile.thumbnailUrl}\nBirthday: ${profile.birthday}');
} catch (error) {
  print('Failed to retrieve Kakao Story profile. $error');
})

profile() returns Kakao Story profile information through the StoryProfile object.

Users can set their desired profile nicknames and images for Kakao Story, Kakao Talk, and Kakao Account respectively. Thus, profile information retrieved through this API is different from the ones obtained through the Retrieving user information API or Retrieving Kakao Talk profile API.

StoryProfile
Name Type Description Required
nickname String Kakao Story nickname.

Required user consent: Profile Info(nickname/profile image) or Nickname
X
profileImageUrl String Kakao Story profile image URL with a size of 480x480 pixels to 1024x1024 pixels.

Required user consent: Profile Info(nickname/profile image) or Profile image
X
thumbnailUrl String Kakao Story thumbnail profile image URL with a size of 160x213 pixels.
Image size can be changed within the range of 160x213 pixels.

Required user consent: Profile Info(nickname/profile image) or Profile image
X
bgImageUrl String Kakao Story background image URL with a size of 480x480 pixels to 1024x1024 pixels.

Required user consent: Profile Info(nickname/profile image) or Profile image
X
permalink String Kakao Story profile URL.

Required user consent: KakaoStory profile URL

NOTE: From June 1, 2021, only when a user consents to 'KakaoStory profile URL(story_permalink)', the Retrieving Kakao Story profile API returns 'permalink' in the response. For more details, see Notice.
X
birthday String Birthday registered in Kakao Story in MMdd format.

Required user consent: Birthday
X
birthdayType String Solar or Lunar birthday.
SOLAR, LUNAR

Required user consent: Birthday
X

Post story

To post a new story on Kakao Story of the user who is currently logged in, call one of the following methods depending on the story type — text, photo, or link. You also must pass arguments for the corresponding story type.

Story types

Type Description Method
Text Story with text only. postNote()
Photo Story with text and photos. postPhoto()
Link Story with text and the information obtained by scrapping a web page. postLink()

Posting text story

Basic information
Permission Prerequisite Kakao Login User consent
- Register platforms
Activate Kakao Login
Manage consent items
Required Required:
Publish posts in KakaoStory

To post a text story without any photo or web page URL, call the postNote() method. You also must pass content for the text type of story.

Parameter
Name Type Description Required
content String Text to be input in the story. O
permission StoryPermission Audience for the story.
- public: Open to all.
- friend: Open to only friends.
- onlyMe: Open to only me (Private).
(Default: public)
X
enableShare Bool Whether to share the story when permission is set to friend (Friends only).
(Default: false)
X
androidExecParam Map<String, String>? Parameter to be added to the URL to execute an Android app when selecting the [View on app] button from Kakao Story. X
iosExecParam Map<String, String>? Parameter to be added to the URL to execute an iOS app when selecting the [View on app] button from Kakao Story. X
androidMarketParam Map<String, String>? Parameter to be added to the execution URL when redirecting to an open market from Kakao Story. X
iosMarketParam Map<String, String>? Parameter to be added to the execution URL when redirecting to the App Store from Kakao Story. X
Sample
// Posting a text story
try {
  String content = "Posting note from Kakao SDK Sample";
  StoryPostResult storyPostResult = await StoryApi.instance.postNote(content: content);
  print('Succeeded in posting a story. [${storyPostResult.id}]');
} catch (error) {
  print('Failed to post a story. $error');
}

Posting photo story

Basic information
Permission Prerequisite Kakao Login User consent
- Register platforms
Activate Kakao Login
Manage consent items
Required Required:
Publish posts in KakaoStory

To post a story with photos,

  1. To use the image files saved on a local device, you need to upload them to the Kakao server first. Call the upload() method by passing images with List<File> type to be posted in a story. upload() returns the list of the uploaded image URLs.
  2. Call the postPhoto() method by passing images that is obtained through upload().
Parameter
Name Type Description Required
images List<String> List of image URLs that is obtained through upload(). O
content String Text to be input in the story.
Up to 2048 characters are allowed.
X
permission StoryPermission Audience for the story.
- public: Open to all.
- friend: Open to only friends.
- onlyMe: Open to only me (Private).
(Default: public)
X
enableShare Bool Whether to share the story when permission is set to friend (Friends only).
(Default: false)
X
androidExecParam Map<String, String>? Parameter to be added to the URL to execute an Android app when selecting the [View on app] button from Kakao Story. X
iosExecParam Map<String, String>? Parameter to be added to the URL to execute an iOS app when selecting the [View on app] button from Kakao Story. X
androidMarketParam Map<String, String>? Parameter to be added to the execution URL when redirecting to an open market from Kakao Story. X
iosMarketParam Map<String, String>? Parameter to be added to the execution URL when redirecting to the App Store from Kakao Story. X
Sample

This code snippet uses the image file added as a project resource. Use the image files as your service needs.

// Uploading an image and posting a photo story with the uploaded 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));

// Upload images.
List<String> images;

try {
  images = await StoryApi.instance.upload([file]);
  print('"Succeeded in uploading image. $images');
} catch (error) {
  print('Failed to upload image. $error');
  return;
}

// Post a photo story.
try {
  String content = 'Posting photo from Kakao SDK Sample.';
  StoryPostResult storyPostResult = await StoryApi.instance.postPhoto(images: images, content: content);
  print('Succeeded in posting a story. [${storyPostResult.id}]');
} catch (error) {
  print('Failed to post a story. $error');
}

Posting link story

Basic information
Permission Prerequisite Kakao Login User consent
- Register platforms
Activate Kakao Login
Manage consent items
Required Required:
Publish posts in KakaoStory

To post a story with the information obtained by scrapping a web page,

  1. To obtain the web page information to be shared in a story, call the linkInfo() method by passing url with a string type. linkInfo() returns the LinkInfo object that contains the web page information scraped based on the Open Graph Protocol.
  2. Call the postLink() method by passing LinkInfo that is obtained through linkInfo().
Parameter
Name Type Description Required
linkInfo LinkInfo The web page information that is obtained through linkInfo(). O
content String Text to be input in the story.
Up to 2048 characters are allowed.
X
permission StoryPermission Audience for the story.
- public: Open to all.
- friend: Open to only friends.
- onlyMe: Open to only me (Private).
(Default: public)
X
enableShare Bool Whether to share the story when permission is set to friend (Friends only).
(Default: false)
X
androidExecParam Map<String, String>? Parameter to be added to the URL to execute an Android app when selecting the [View on app] button from Kakao Story. X
iosExecParam Map<String, String>? Parameter to be added to the URL to execute an iOS app when selecting the [View on app] button from Kakao Story. X
androidMarketParam Map<String, String>? Parameter to be added to the execution URL when redirecting to an open market from Kakao Story. X
iosMarketParam Map<String, String>? Parameter to be added to the execution URL when redirecting to the App Store from Kakao Story. X
LinkInfo
Name Type Description Required
url String URL of of the scrapped web page.
In the case of a shortened link, the resolved URL.
X
requestedUrl String Original URL of the scrapped web page.
In the case of a shortened link, the original URL before resolving it.
X
host String Site domain of the scrapped web page. X
title String Title of the scrapped web page. X
images List<String> List of representative images on the scrapped web page.
Up to three images are allowed.
X
description String Description of the scrapped web page. X
section String Section information of the scrapped web page. X
type String Content type of the scrapped web page such as video, music, book, article, profile, and website. X
Sample

The following code snippet shows the algorithm for scraping web page and posting a link story with the scrapped web page information.

// Posting a link story

LinkInfo linkInfo;

// Create link info with the specified URL.
try {
  linkInfo = await StoryApi.instance.linkInfo('https://www.kakaocorp.com');
  print('Succeeded in creating link info. ${linkInfo.title}');
} catch (error) {
  print('Failed to create link info. $error');
  return;
}

// Post a link story with the obtained link information.
String content = 'Posting link from Kakao SDK Sample.';

try {
  StoryPostResult storyPostResult = await StoryApi.instance.postLink(linkInfo: linkInfo, content: content);
  print('Succeeded in posting a story. [${storyPostResult.id}]');
} catch (error) {
  print('Failed to post a story. $error');
}

The methods to post a story return the StoryPostResult object.

StoryPostResult
Name Type Description
id String ID of the uploaded story.

Retrieve my story

Basic information
Permission Prerequisite Kakao Login User consent
- Register platforms
Activate Kakao Login
Manage consent items
Required Required:
Read access to KakaoStory posts

To retrieve story information on Kakao Story of the user currently logged in, call the stories() method in the StoryApi class.

To retrieve the detailed information of a specific story, call the story() method by passing storyId.

Sample: Retrieving a specific story
try {
  Story story = await StoryApi.instance.story(storyId);
  print('Succeeded in retrieving the story. \nStory ID: ${story.id}\nMedia type: ${story.mediaType}\nPost date: ${story.createdAt}\nContent: ${story.content}');
} catch (error) {
  print('Failed to retrieve the story. $error');
}
Sample: Retrieving all stories of the user
try {
  List<Story> stories = await StoryApi.instance.stories();
  print('Succeeded in retrieving the stories. \n$stories');
} catch (error) {
  print('Failed to retrieve the stories. $error');
}
Sample: Retrieving all stories and getting first story information

The following code snippet shows the algorithm for retrieving all stories of the user and getting the information of the first story.

List<Story> stories;
try {
  stories = await StoryApi.instance.stories();
} catch (error) {
  return;
}

if (stories.isEmpty) {
  print('There is no story :(');
  return;
}

// The story ID to be retrieved
String storyId = stories.first.id;

// Retrieving the first story by designating the story ID.
try {
  Story story = await StoryApi.instance.story(storyId);
  print('Succeeded in retrieving the story. \nStory ID: ${story.id}\nMedia type: ${story.mediaType}\nPost date: ${story.createdAt}\nContent: ${story.content}');
} catch (error) {
  print('Failed to retrieve Kakao Story. $error ');
}

story() returns the Story object, and stories() returns a list of Story objects that contains each story information. stories() does not return comments and likes that are only returned through story().

Story
Name Type Description Required
id String Story ID. O
url String Story URL. O
content String Story content. O
createdAt DateTime The time when the story is posted in RFC3339 internet date/time format. O
mediaType StoryType Story type.
One of photo (photo), note (text), notSupported (not supported).
X
media List<StoryImage> URLs by image size.
Only returned if mediaType is photo.
X
commentCount Int Number of comments. O
likeCount Int Number of moods that the user's friends left. O
permission StoryPermission Audience for the story.
- public: Open to all.
- friend: Open to only friends.
- onlyMe: Open to only me (Private).
(Default: public)
X
comments List<StoryComment> List of comments consisting of text (content) and writer (the user who left the comment).
NOTE: Not returned if stories() is called.
X
likes List<StoryLike> List of moods consisting of emotion (mood emoji) and actor (the user who left the mood).
NOTE: Not returned if stories() is called.
X
StoryImage
Name Type Description Required
large String URL of the image with a size of 720x960 pixels. X
medium String URL of the image with a size of 240x320 pixels. X
original String URL of the original image. X
small String URL of the image with a size of 160x213 pixels. X
xlarge String URL of the image with a size of 1280x1706 pixels. X
StoryComment
Name Type Description Required
text String Comment content. O
writer StoryActor User who left a comment. O
StoryLike
Name Type Description Required
emotion Emotion Mood left in a story.
One of like, cool, happy, sad, cheerUp.
O
actor StoryActor User who left the mood. O
StoryActor
Name Type Description Required
displayName String User's Kakao Story nickname. O
profileThumbnailUrl String User's Kakao Story profile thumbnail URL. X

Delete story

Basic information
Permission Prerequisite Kakao Login User consent
- Register platforms
Activate Kakao Login
Manage consent items
Required Required:
Read access to KakaoStory posts

To delete a story on a user's Kakao Story, call the delete() method in the StoryApi class. You must pass id to specify the story ID you want to delete.

Parameter
Name Type Description Required
id String Story ID to be deleted.
If you do not know the story ID, call the Retrieving my story API.
O
Sample

The following code snippet shows the algorithm for retrieving all stories of the user and deleting the first story.

// Deleting a specific story

List<Story> stories;

// Retrieving all stories 
try {
  stories = await StoryApi.instance.stories();
} catch (error) {
  print('Failed to retrieve stories. $error');
  return;
}

if (stories.isEmpty) {
  print('There is no story :(');
  return;
}

// The story ID to be deleted
String storyId = stories.first.id;


// Deleting a story
try {
  await StoryApi.instance.delete(storyId);
  print('Succeeded in deleting story. [$storyId]');
} catch (error) {
  print('Failed to delete story. $error');
}

See more