liff-init.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // ----- Configuration Zone! -----
  2. // Don't forget to change this to your LIFF ID
  3. const liffId = "1657885870-r249Ky1K";
  4. // Don't forget to change this to your LIFF ID
  5. liff.init(
  6. { liffId: liffId },
  7. () => {
  8. initLIFF();
  9. },
  10. err => {
  11. window.alert(err);
  12. }
  13. );
  14. function initLIFF() {
  15. if (liff.isLoggedIn()) {
  16. liff
  17. .getProfile()
  18. .then(profile => {
  19. document.getElementById("profileImage").src = profile.pictureUrl;
  20. // document.getElementById("userId").innerHTML = profile.userId;
  21. // document.getElementById("displayName").innerHTML = profile.displayName;
  22. // document.getElementById("statusMessage").innerHTML =
  23. // profile.statusMessage;
  24. // document.getElementById("pictureUrl").href = profile.pictureUrl;
  25. // document.getElementById("pictureUrl").innerHTML = profile.pictureUrl;
  26. // document.getElementById(
  27. // "email"
  28. // ).innerHTML = liff.getDecodedIDToken().email;
  29. })
  30. .catch(e => {
  31. // document.getElementById("userId").innerHTML = "No data, " + e;
  32. // document.getElementById("displayName").innerHTML = "No data, " + e;
  33. // document.getElementById("statusMessage").innerHTML = "No data, " + e;
  34. // document.getElementById("pictureUrl").innerHTML = "No data, " + e;
  35. //document.getElementById("email").innerHTML = "No data, " + e;
  36. });
  37. } else {
  38. // document.getElementById("userId").innerHTML = "No data, Login first";
  39. // document.getElementById("displayName").innerHTML = "No data, Login first";
  40. // document.getElementById("statusMessage").innerHTML = "No data, Login first";
  41. // document.getElementById("pictureUrl").innerHTML = "No data, Login first";
  42. // document.getElementById("email").innerHTML = "No data, Login first";
  43. }
  44. // document.getElementById("getOS").innerHTML = liff.getOS();
  45. //document.getElementById("getLanguage").innerHTML = liff.getLanguage();
  46. // document.getElementById("getVersion").innerHTML = liff.getVersion();
  47. // document.getElementById("isInClient").innerHTML = liff.isInClient();
  48. //document.getElementById("isLoggedIn").innerHTML = liff.isLoggedIn();
  49. var context = liff.getContext();
  50. if (context !== null) {
  51. // document.getElementById("context_type").innerHTML = context.type;
  52. // document.getElementById("context_viewType").innerHTML = context.viewType;
  53. // document.getElementById("context_userId").innerHTML = context.userId;
  54. if (context.utouId) {
  55. // document.getElementById("context_utouId").innerHTML = context.utouId;
  56. } else {
  57. // document.getElementById("context_utouId").innerHTML =
  58. // "You are not in the utou";
  59. }
  60. if (context.roomId) {
  61. // document.getElementById("context_roomId").innerHTML = context.roomId;
  62. } else {
  63. // document.getElementById("context_roomId").innerHTML =
  64. // "You are not in the room";
  65. }
  66. if (context.groupId) {
  67. // document.getElementById("context_groupId").innerHTML = context.groupId;
  68. } else {
  69. // document.getElementById("context_groupId").innerHTML =
  70. // "You are not in the group ";
  71. }
  72. } else {
  73. // document.getElementById("context_type").innerHTML = "No data.";
  74. // document.getElementById("context_viewType").innerHTML = "No data.";
  75. // document.getElementById("context_userId").innerHTML = "No data.";
  76. // document.getElementById("context_utouId").innerHTML = "No data.";
  77. //document.getElementById("context_roomId").innerHTML = "No data.";
  78. // document.getElementById("context_groupId").innerHTML = "No data.";
  79. }
  80. }