Skip to content

Instantly share code, notes, and snippets.

@jirawatee
Last active November 27, 2022 05:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jirawatee/6b9b581143832a4e713b9504028dade9 to your computer and use it in GitHub Desktop.
Save jirawatee/6b9b581143832a4e713b9504028dade9 to your computer and use it in GitHub Desktop.
LIFF v2 Sample Code
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My LIFF v2</title>
<style>
#pictureUrl { display: block; margin: 0 auto }
</style>
</head>
<body>
<img id="pictureUrl" width="25%">
<p id="userId"></p>
<p id="displayName"></p>
<p id="statusMessage"></p>
<p id="getDecodedIDToken"></p>
<script src="https://static.line-scdn.net/liff/edge/versions/2.9.0/sdk.js"></script>
<script>
function runApp() {
liff.getProfile().then(profile => {
document.getElementById("pictureUrl").src = profile.pictureUrl;
document.getElementById("userId").innerHTML = '<b>UserId:</b> ' + profile.userId;
document.getElementById("displayName").innerHTML = '<b>DisplayName:</b> ' + profile.displayName;
document.getElementById("statusMessage").innerHTML = '<b>StatusMessage:</b> ' + profile.statusMessage;
document.getElementById("getDecodedIDToken").innerHTML = '<b>Email:</b> ' + liff.getDecodedIDToken().email;
}).catch(err => console.error(err));
}
liff.init({ liffId: "YOUT-LIFF-ID" }, () => {
if (liff.isLoggedIn()) {
runApp()
} else {
liff.login();
}
}, err => console.error(err.code, error.message));
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment