liff-init.js 3.6 KB

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