페이지 이동경로
  • 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').

Tag used in this document

Tag Description
Login required The API marked with this tag requires Kakao Login. You must implement the Kakao Login function first, and then call the corresponding API by using the access token issued when a user logs in.
Consent required To use the API marked with this tag, you must enable a specific scope required for the corresponding API.
In addition, a user also must consent to the scope. Otherwise, an error occurs or empty value is returned. To check which scopes a user has consented to, you can call the Retrieving consent details API.

Before you begin

Before using Kakao Story APIs with the Flutter SDK,

  1. Complete the prerequisites.
  2. Implement Kakao Login for the token-based APIs. To obtain the tokens, a user also must be logged in with Kakao. For more information, refer to Understand Concepts > Kakao Login.
  3. After adding kakao_flutter_sdk_story and kakao_flutter_sdk_user in pubspec.yaml by referring to Install SDK, add the following libraries in your dart file.
    import 'package:kakao_flutter_sdk_user/kakao_flutter_sdk_user.dart';
    import 'package:kakao_flutter_sdk_story/kakao_flutter_sdk_story.dart';
    
  4. Set Custom URL Scheme in AndroidManifest.xml.

Validate Kakao Story user Login 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 (e) {
  print('Failed to validate Kakao Story user registration. $e');
}
Return data

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 Login required Consent required

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 (e) {
  print('Failed to retrieve Kakao Story profile.');
})
Return data

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

The profile information retrieved through this API may be different from the profiles obtained through the Retrieving user information API or Retrieving Kakao Talk profile API since users can set their profile nicknames and images respectively for Kakao Story, Kakao Talk, and Kakao Account.

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 Login required Consent required

To use this API,

  • You must enable the 'Publish posts in KakaoStory' scope in [My Application] > [Kakao Login] > [Consent items].
  • A user must consent to the scope.

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

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 (e) {
  print('Failed to post a story. $e');
}

Posting photo story

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 (e) {
  print('Failed to upload image. $e');
  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 (e) {
  print('Failed to post a story. $e');
}

Posting link story

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 (e) {
  print('Failed to create link info.');
  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 (e) {
  print('Failed to post a story. $e');
}
Return data

The methods to post a story return the StoryPostResult object.

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

Retrieve story Login requiredConsent required

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.

To use this API,

  • You must enable the 'Read access to KakaoStory posts' scope in [My Application] > [Kakao Login] > [Consent items].
  • A user must consent to the 'Read access to KakaoStory posts' scope.
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 (e) {
  print('Failed to retrieve the story. $e');
}
Sample: Retrieving all stories of the user
try {
  List<Story> stories = await StoryApi.instance.stories();
  print('Succeeded in retrieving the stories. \n$stories');
} catch (e) {
  print('Failed to retrieve the stories. $e');
}
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 (e) {
  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 (e) {
  print('Failed to retrieve Kakao Story. ');
}
Return data

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
StoryComments
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

Deleting story Login required

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 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 (e) {
  print('Failed to retrieve stories.');
  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 (e) {
  print('Failed to delete story. $e');
}

See more