iT邦幫忙

0

LineBot Liff表單沒反應

toad 2022-05-06 21:57:161604 瀏覽
  • 分享至 

  • xImage

各位好~我想請問一下為甚麼我的Liff表單在LineBOT按下確認後卻不會有任何的反應
我在前陣子上傳到Heroku後按確認是可以正常推播訊息的
但是現在卻不行了,還請各位告訴我我是不是程式碼或Line那邊沒有設置好。
Heroku連結
https://liff0506.herokuapp.com/index_form.html
Liff設置
https://ithelp.ithome.com.tw/upload/images/20220506/20146572UffszgSWv1.png
程式碼(完整程式碼請點選Heroku查看)

<script>
		function initializeApp(data) {  //初始化LIFF
			var userid = data.context.userId;  //取得ID
		}

		function pushMsg(Pcpu, Pmotherboard, Pssd, Phdd, Pgpu, Pmemory, Ppower, Pcase) {

			var msg = "###";  //回傳訊息字串
			msg = msg + Pcpu + "#";
			msg = msg + Pmotherboard + "#";
			msg = msg + Pssd + "#";
			msg = msg + Phdd + "#";
			msg = msg + Pgpu + "#";
			msg = msg + Pmemory + "#";
			msg = msg + Ppower + "#";
			msg = msg + Pcase + "#";

			liff.sendMessages([  //推播訊息
				{
					type: 'text',
					text: msg
				}
			])
				.then(() => {
					liff.closeWindow();  //關閉視窗
				});
		}

		$(document).ready(function () {
			liff.init(function (data) {  //初始化LIFF
				initializeApp(data);
			});

			$('#sure').click(function (e) {  //按下確定鈕
				pushMsg($('#cpu').val(), $('#motherboard').val(), $('#ssd').val(), $('#hdd').val(), $('#gpu').val(), $('#memory').val(), $('#power').val(), $('#case').val());
			});
		});
	</script>
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 個回答

1
Han
iT邦研究生 1 級 ‧ 2022-05-06 23:03:29
最佳解答
Request URL: https://d.line-scdn.net/liff/1.0/sdk.js
Request Method: GET
Status Code: 404 
Remote Address: 96.7.252.206:443
Referrer Policy: strict-origin-when-cross-origin

發現你還在引用舊的 liff sdk
請先升級到 https://static.line-scdn.net/liff/edge/2/sdk.js

升級好之後再來確認是不是有使用上的錯誤

看更多先前的回應...收起先前的回應...
toad iT邦新手 5 級 ‧ 2022-05-07 11:02:49 檢舉

您好我已經引用新的sdk了
更改程式碼之後也沒有出現錯誤了
但是按下確認後還是沒有反應
還請大神告訴我我哪裡寫錯了/images/emoticon/emoticon41.gif
以下是我的程式碼

<script>
    // Using a Promise object
    function initializeApp() {
        liff
            .init({
                liffId: "1656626380-X2wAEQ6W", // Use own liffId
            })
            .getProfile()
            .then((profile) => {
                const userId = profile.userId;
            })
            .catch((err) => {
                // Error happens during initialization
                console.log(err.code, err.message);
            });

        // Using a callback
        liff.init({ liffId: "1656626380-X2wAEQ6W" }, successCallback, errorCallback);
    }

    
    function pushMsg(Pcpu, Pmotherboard, Pssd, Phdd, Pgpu, Pmemory, Ppower, Pcase) {

        var msg = "###";  //回傳訊息字串
        msg = msg + Pcpu + "#";
        msg = msg + Pmotherboard + "#";
        msg = msg + Pssd + "#";
        msg = msg + Phdd + "#";
        msg = msg + Pgpu + "#";
        msg = msg + Pmemory + "#";
        msg = msg + Ppower + "#";
        msg = msg + Pcase + "#";

        liff.sendMessages([  //推播訊息
            {
                type: 'text',
                text: msg
            }
        ])
            .then(() => {
                liff.closeWindow();  //關閉視窗
            });
    }

    liff.ready.then(() => {
        $('#sure').click(function (e) {  //按下確定鈕
            pushMsg($('#cpu').val(), $('#motherboard').val(),
                $('#ssd').val(), $('#hdd').val(), $('#gpu').val(),
                $('#memory').val(), $('#power').val(), $('#case').val());
        });

    });
</script>
Han iT邦研究生 1 級 ‧ 2022-05-07 15:55:33 檢舉

我有實際去你貼的網址看,一樣是舊版的 sdk

toad iT邦新手 5 級 ‧ 2022-05-07 16:49:09 檢舉

喔喔抱歉~上面的連結我有更新了
現在是對的連結了
它現在是不知道為甚麼按下確認後
都不會有反應~拜託大大為我解答我已經苦惱了好久/images/emoticon/emoticon06.gif

Han iT邦研究生 1 級 ‧ 2022-05-07 19:39:45 檢舉

你的 liff 設定裡面設定的網址是?
正常來說用手機的話要透過這個網址進入
https://liff.line.me/1656626380-X2wAEQ6W

我進去後嘗試在電腦上面使用 liff.sendMessage
有出現以下錯誤訊息,你可能確認一下後台的 Line Login
有沒有如我下圖所示的設定
user doesn't grant required permissions yet

權限設定

toad iT邦新手 5 級 ‧ 2022-05-07 20:52:46 檢舉

我的url是跟上面的連結是一樣的
https://ithelp.ithome.com.tw/upload/images/20220507/201465728letVpgyZu.png

toad iT邦新手 5 級 ‧ 2022-05-07 20:53:23 檢舉

https://ithelp.ithome.com.tw/upload/images/20220507/20146572RgdlfLZlik.png

Han iT邦研究生 1 級 ‧ 2022-05-07 22:46:54 檢舉

這樣可能要測試看看你按鈕事件有沒有確實觸發哦
可以在你 pushMsg 裡面加個 alert('test') 試試看

toad iT邦新手 5 級 ‧ 2022-05-07 23:07:34 檢舉

所以程式碼看起來是沒問題的嗎?

Han iT邦研究生 1 級 ‧ 2022-05-08 13:20:52 檢舉

看起來沒問題,唯一不確定的是你原本用以下來綁定事件
$("#sure").click(function(e) {})

但我比較常用
$(document).on('click', '#sure', function() {})
這種方式來綁定事件

不過看你後來改寫成原生 js 的用法,就看你有沒有測試成功囉

toad iT邦新手 5 級 ‧ 2022-05-08 13:29:53 檢舉

好的謝謝你
我後來測試後已經正常了。

0
fred0908
iT邦見習生 ‧ 2022-05-18 14:54:38

大大我也遇到這個問題
我依造你們回覆的內容處理但還是沒反應..
請問我還有哪裡需要更改的嗎?
Heroku連結
https://ebc-leave.herokuapp.com/index_form.html
https://ithelp.ithome.com.tw/upload/images/20220518/20149098n6EsC5LZMf.jpg
https://ithelp.ithome.com.tw/upload/images/20220518/20149098nYrRofmUMH.jpg
https://ithelp.ithome.com.tw/upload/images/20220518/2014909877oDKY0NEe.jpg

我要發表回答

立即登入回答