返回列表 上一主題 發帖

[發問] 使用excel vba上傳圖檔到line

[發問] 使用excel vba上傳圖檔到line

關於line notify應用, 請問要怎麼把圖檔送到line的群組裡面?
圖檔路徑是F:\test.png
我參考https://notify-bot.line.me/doc/en/ 官網的說明,
裡面有提到要用imagefile, 但仍不知如何下手
請各位前輩指教@@

附上原始碼
  1. Sub line_notify_圖片()   
  2.      '===================================
  3.     'Line訊息
  4.     '===================================
  5.     Dim oXML As Object
  6.    
  7.     Dim Token As String
  8.    
  9.     Dim URL As String
  10.    
  11.     '指定的Line Notify Token
  12.    
  13.     Token = "你的TOKEN"
  14.    
  15.     'Line Notify的傳送訊息網址
  16.        
  17.         Line_Message = "str test"
  18.    
  19.     URL = "https://notify-api.line.me/api/notify"

  20.     Set oXML = CreateObject("Microsoft.XMLHTTP")
  21.    
  22.     With oXML
  23.    
  24.         '使用同步傳輸
  25.    
  26.         .Open "POST", URL, 0
  27.    
  28.         '設定傳送封包Header
  29.    
  30.         .SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
  31.    
  32.         .SetRequestHeader "Authorization", "Bearer " & Token
  33.    
  34.         '執行Ajax傳送
  35.         .send "message=" & Chr(10) & Line_Message
  36.         Debug.Print oXML.responseText
  37.    
  38.     End With
  39.    
  40.     '釋放物件資源
  41.    
  42.     Set oXML = Nothing
  43. End Sub
複製代碼

本帖最後由 singo1232001 於 2023-2-15 22:21 編輯

回復 18# 7777


    我也覺得要跑兩次

要寫迴圈  代入圖片位置變數

而且 大量傳送 要記得放等待緩衝時間  不然傳太快 會被line notify 的API ban 30分鐘

我自己測試 是每傳一次 會設定等待5秒     可以用application.wait now+timevalue("00:00:05") 的方式

要是沒寫等待

測到沒反應 基本上就是直接猜 被ban了  只能等30分鐘

TOP

回復 18# 7777


https://notify-bot.line.me/doc/en/
LINE Notify API 沒這個功能吧,我想到的只有跑2次curl
我沒研究line api,其它的我不會

TOP

本帖最後由 7777 於 2023-2-15 20:49 編輯

回復 16# quickfixer


    再請教
一次傳送兩個圖片


Sub Sample()
Dim msg As String: msg = "你好"
Dim imgPath1 As String: imgPath1 = "C:\Users\hoge\Desktop\test.jpg"
Dim imgPath2 As String: imgPath2 = "C:\Users\hoge\Desktop\testa1.jpg"
Dim cmd As String: cmd = "C:\installations\curl.exe" & _                  ' or    cmd = "curl.exe" & _       '目前的 curl.exe 放在C:\installations\
" -X POST https://notify-api.line.me/api/notify" & _
" -H ""Authorization: Bearer 5Cx15az4Ka1Gl3idjF5kxYmHg13Ja1xOWsRPkzMaLPh""" & _
" -F message=" & msg & _
" -F imageFile1=@" & imgPath1 & _
" -F imageFile2=@" & imgPath2
Shell cmd, vbNormalFocus
End Sub


試了幾次都無法動作,還可以怎麼修改?

謝謝
50 字節以內
不支持自定義 Discuz! 代碼

TOP

回復 16# quickfixer


    收到~
         感恩
50 字節以內
不支持自定義 Discuz! 代碼

TOP

回復 15# 7777


    變數不能放在雙引號裡面,會變字串
"wwwwww   變數  wwwwww"

要放在外面用 & 連接
"wwwwww" & 變數 & "wwwwww"

TOP

本帖最後由 7777 於 2023-2-13 10:53 編輯

回復 13# quickfixer


        再問我想將 "LINE權杖"改成 a1储存格,就出現問題無作業,可以幫我解決問題嗎?謝謝

Sub Sample()

Dim AccessToken As String :AccessToken = Sheets("工作表1").Range("a1")

Dim msg As String: msg = "你好"
Dim imgPath As String: imgPath = "C:\Users\hoge\Desktop\test.jpg"
Shell "curl.exe" & _
" -X POST https://notify-api.line.me/api/notify" & _
" -H ""Authorization: Bearer AccessToken""" & _
" -F message=" & msg & _
" -F imageFile=@" & imgPath, vbNormalFocus

End Sub




' 這是ok的 沒圖
Dim AccessToken As String :AccessToken = Sheets("工作表1").Range("a1")     'LINE權杖
Dim msgString As String :msgString = Sheets("工作表1").Range("a2")         'LINE訊息
                        
    '建立Ajax物件
    Set oXML = CreateObject("Microsoft.XMLHTTP")
    With oXML
        '使用同步傳輸
        .Open "POST", "https://notify-api.line.me/api/notify", 0

        '設定傳送封包Header
        .SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
        .SetRequestHeader "Authorization", "Bearer " & AccessToken
        '執行Ajax傳送
        .send "message=" & msgString
        
        '顯示回報內容
        Debug.Print oXML.responseText
    End With
50 字節以內
不支持自定義 Discuz! 代碼

TOP

回復 13# quickfixer


    感恩
這版~~~
確實可以 秀出中文了
50 字節以內
不支持自定義 Discuz! 代碼

TOP

回復 11# 7777

這個版本正常傳中文
    https://github.com/tim-lebedkov/packages/releases/download/2020_12/se.haxx.curl.CURL64-7.74-curl-7.74.0-win64-mingw.zip

TOP

回復 11# 7777


    找到原因了,新版的curl會亂碼
舊版的不會

TOP

        靜思自在 : 口說一句好話,如口出蓮花;口說一句壞話如口吐毒蛇。
返回列表 上一主題