liff-init.js 3.7 KB

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