Board logo

標題: [發問] 使用excel vba上傳圖檔到line [打印本頁]

作者: s13983037    時間: 2020-4-15 21:55     標題: 使用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
複製代碼

作者: yws0915    時間: 2022-3-2 11:50

資料來源https://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q11237902231
  1. Sub Sample()
  2. Dim msg As String: msg = "Hello"
  3. Dim imgPath As String: imgPath = "C:\Users\hoge\Desktop\test.jpg"
  4. Shell "curl.exe" & _
  5. " -X POST https://notify-api.line.me/api/notify" & _
  6. " -H ""Authorization: Bearer 5Cx15az4Ka1Gl3idjF5kxYmHg13Ja1xOWsRPkzMaLPh""" & _
  7. " -F message=" & msg & _
  8. " -F imageFile=@" & imgPath, vbNormalFocus

  9. End Sub
複製代碼

作者: 7777    時間: 2023-2-10 12:08

回復 2# yws0915


    問題是我想將msg="Hello"改成中文,msg="你好"就出現問題,可以幫我解決問題嗎?謝謝

Sub Sample()
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 5Cx15az4Ka1Gl3idjF5kxYmHg13Ja1xOWsRPkzMaLPh""" & _
" -F message=" & msg & _
" -F imageFile=@" & imgPath, vbNormalFocus

End Sub
作者: singo1232001    時間: 2023-2-10 14:14

回復 3# 7777


    " -F message=" & msg & _

改成

" -F message=" & WorksheetFunction.EncodeURL(msg) & _
作者: 7777    時間: 2023-2-10 15:12

回復 4# singo1232001


    感謝

修改後 出現 圖1

[attach]35818[/attach]
作者: singo1232001    時間: 2023-2-11 07:32

本帖最後由 singo1232001 於 2023-2-11 07:36 編輯

回復 5# 7777

http://white5168.blogspot.com/2017/01/line-notify-6-line-notify.html#.Y-bI8nZBxPY
我查了一下


我建議 分段傳
圖片用curl 這段 好像只支援 日 韓 英

傳完圖片
等五秒
再用正常的傳訊方式傳訊息

但圖片的部分 我還沒測試成功
看到要server才能傳 目前我的功力跟基礎不夠

不過 看他056 這行 確實可以用中文字傳送    arr2 = Utf8BytesFromString("小天使圖傳送!!!LaLaLa~~~")
最後也有顯示中文

再參考看看
作者: quickfixer    時間: 2023-2-12 06:01

回復 5# 7777


我用你的程式碼測中文字,正常輸出
win10

[attach]35830[/attach]

[attach]35831[/attach]
作者: 7777    時間: 2023-2-12 12:03

回復 7# quickfixer


    感謝解說~~

不懂!!
試了很多次,還是都不成功,
這跟電腦環境有差嗎??
win10 ,2019 版本office  64位元 (應該OK)
還是需要安裝什麼 ??
作者: 7777    時間: 2023-2-12 12:42

回復 7# quickfixer


    測試的三台電腦皆不行,英文都OK
作者: quickfixer    時間: 2023-2-12 15:08

回復 9# 7777

試了win7 office2016
Win10 office2019,都正常,只装curl
其它都是剛重灌好

測試用手機是android系統
作者: 7777    時間: 2023-2-12 20:28

回復 10# quickfixer


    https://www.jack168.com/download/curl/curl.html
照做
安裝好curl
重開機後,興奮的執行
結果仍然不行

依舊感謝
作者: quickfixer    時間: 2023-2-12 20:52

回復 11# 7777


    找到原因了,新版的curl會亂碼
舊版的不會
作者: quickfixer    時間: 2023-2-12 23:12

回復 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
作者: 7777    時間: 2023-2-12 23:36

回復 13# quickfixer


    感恩
這版~~~
確實可以 秀出中文了

作者: 7777    時間: 2023-2-13 10:51

本帖最後由 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

作者: quickfixer    時間: 2023-2-13 20:30

回復 15# 7777


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

要放在外面用 & 連接
"wwwwww" & 變數 & "wwwwww"
作者: 7777    時間: 2023-2-13 22:46

回復 16# quickfixer


    收到~
         感恩

作者: 7777    時間: 2023-2-15 20:44

本帖最後由 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


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

謝謝

作者: quickfixer    時間: 2023-2-15 21:58

回復 18# 7777


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

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

回復 18# 7777


    我也覺得要跑兩次

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

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

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

要是沒寫等待

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




歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)