麻辣家族討論版版's Archiver

s13983037 發表於 2020-4-15 21:55

使用excel vba上傳圖檔到line

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

附上原始碼[code]Sub line_notify_圖片()   
     '===================================
    'Line訊息
    '===================================
    Dim oXML As Object
   
    Dim Token As String
   
    Dim URL As String
   
    '指定的Line Notify Token
   
    Token = "你的TOKEN"
   
    'Line Notify的傳送訊息網址
       
        Line_Message = "str test"
   
    URL = "https://notify-api.line.me/api/notify"

    Set oXML = CreateObject("Microsoft.XMLHTTP")
   
    With oXML
   
        '使用同步傳輸
   
        .Open "POST", URL, 0
   
        '設定傳送封包Header
   
        .SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
   
        .SetRequestHeader "Authorization", "Bearer " & Token
   
        '執行Ajax傳送
        .send "message=" & Chr(10) & Line_Message
        Debug.Print oXML.responseText
   
    End With
   
    '釋放物件資源
   
    Set oXML = Nothing
End Sub[/code]{:3_57:}

yws0915 發表於 2022-3-2 11:50

資料來源https://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q11237902231[code]Sub Sample()
Dim msg As String: msg = "Hello"
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[/code]

7777 發表於 2023-2-10 12:08

[b]回復 [url=http://forum.twbts.com/redirect.php?goto=findpost&pid=118495&ptid=22487]2#[/url] [i]yws0915[/i] [/b]


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

Sub Sample()
Dim msg As String: [b][color=Red]msg = "你好"[/color][/b]
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

[b]回復 [url=http://forum.twbts.com/redirect.php?goto=findpost&pid=120414&ptid=22487]3#[/url] [i]7777[/i] [/b]


    " -F message=" & msg & _

改成

" -F message=" & WorksheetFunction.EncodeURL(msg) & _

7777 發表於 2023-2-10 15:12

[b]回復 [url=http://forum.twbts.com/redirect.php?goto=findpost&pid=120417&ptid=22487]4#[/url] [i]singo1232001[/i] [/b]


    感謝

修改後 出現 圖1

[attach]35818[/attach]

singo1232001 發表於 2023-2-11 07:32

[i=s] 本帖最後由 singo1232001 於 2023-2-11 07:36 編輯 [/i]

[b]回復 [url=http://forum.twbts.com/redirect.php?goto=findpost&pid=120419&ptid=22487]5#[/url] [i]7777[/i] [/b]

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

[b]回復 [url=http://forum.twbts.com/redirect.php?goto=findpost&pid=120419&ptid=22487]5#[/url] [i]7777[/i] [/b]


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

[attach]35830[/attach]

[attach]35831[/attach]

7777 發表於 2023-2-12 12:03

[b]回復 [url=http://forum.twbts.com/redirect.php?goto=findpost&pid=120448&ptid=22487]7#[/url] [i]quickfixer[/i] [/b]


    感謝解說~~

不懂!!
試了很多次,還是都不成功,
這跟電腦環境有差嗎??
win10 ,2019 版本office  64位元 (應該OK)
[b]還是需要安裝什麼 ??[/b]

7777 發表於 2023-2-12 12:42

[b]回復 [url=http://forum.twbts.com/redirect.php?goto=findpost&pid=120448&ptid=22487]7#[/url] [i]quickfixer[/i] [/b]


[b][size=4]    測試的三台電腦皆不行,英文都OK[/size][/b]

quickfixer 發表於 2023-2-12 15:08

[b]回復 [url=http://forum.twbts.com/redirect.php?goto=findpost&pid=120450&ptid=22487]9#[/url] [i]7777[/i] [/b]

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

測試用手機是android系統

7777 發表於 2023-2-12 20:28

[b]回復 [url=http://forum.twbts.com/redirect.php?goto=findpost&pid=120453&ptid=22487]10#[/url] [i]quickfixer[/i] [/b]


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

依舊感謝

quickfixer 發表於 2023-2-12 20:52

[b]回復 [url=http://forum.twbts.com/redirect.php?goto=findpost&pid=120457&ptid=22487]11#[/url] [i]7777[/i] [/b]


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

quickfixer 發表於 2023-2-12 23:12

[b]回復 [url=http://forum.twbts.com/redirect.php?goto=findpost&pid=120457&ptid=22487]11#[/url] [i]7777[/i] [/b]

這個版本正常傳中文
    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

[b]回復 [url=http://forum.twbts.com/redirect.php?goto=findpost&pid=120461&ptid=22487]13#[/url] [i]quickfixer[/i] [/b]


[b][size=6]    感恩
這版~~~
確實可以 秀出中文了[/size][/b]

7777 發表於 2023-2-13 10:51

[i=s] 本帖最後由 7777 於 2023-2-13 10:53 編輯 [/i]

[b]回復 [url=http://forum.twbts.com/redirect.php?goto=findpost&pid=120461&ptid=22487]13#[/url] [i]quickfixer[/i] [/b]


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

Sub Sample()

Dim AccessToken As String :[color=Blue][b]AccessToken [/b][/color]= 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 [color=Blue][b]AccessToken[/b][/color]""" & _
" -F message=" & msg & _
" -F imageFile=@" & imgPath, vbNormalFocus

End Sub




[color=Gray]' 這是ok的 沒圖
Dim AccessToken As String :[color=Blue][b]AccessToken [/b][/color]= 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 " & [color=Blue][b]AccessToken[/b][/color]
        '執行Ajax傳送
        .send "message=" & msgString
        
        '顯示回報內容
        Debug.Print oXML.responseText
    End With[/color]

quickfixer 發表於 2023-2-13 20:30

[b]回復 [url=http://forum.twbts.com/redirect.php?goto=findpost&pid=120466&ptid=22487]15#[/url] [i]7777[/i] [/b]


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

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

7777 發表於 2023-2-13 22:46

[b]回復 [url=http://forum.twbts.com/redirect.php?goto=findpost&pid=120469&ptid=22487]16#[/url] [i]quickfixer[/i] [/b]


[b][size=3]    收到~
         感恩[/size][/b]

7777 發表於 2023-2-15 20:44

[i=s] 本帖最後由 7777 於 2023-2-15 20:49 編輯 [/i]

[b]回復 [url=http://forum.twbts.com/redirect.php?goto=findpost&pid=120469&ptid=22487]16#[/url] [i]quickfixer[/i] [/b]


[b][size=3]    再請教
一次傳送兩個圖片[/size][/b]

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" & _                  [color=Green]'[b] or[/b]    cmd = "curl.exe" & _       '目前的 curl.exe 放在C:\installations\[/color]
" -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


[b][size=3]試了幾次都無法動作,還可以怎麼修改?

謝謝[/size][/b]

quickfixer 發表於 2023-2-15 21:58

[b]回復 [url=http://forum.twbts.com/redirect.php?goto=findpost&pid=120486&ptid=22487]18#[/url] [i]7777[/i] [/b]


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

singo1232001 發表於 2023-2-15 22:19

[i=s] 本帖最後由 singo1232001 於 2023-2-15 22:21 編輯 [/i]

[b]回復 [url=http://forum.twbts.com/redirect.php?goto=findpost&pid=120486&ptid=22487]18#[/url] [i]7777[/i] [/b]


    我也覺得要跑兩次

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

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

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

要是沒寫等待

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

頁: [1]

麻辣家族討論版版為 麻辣學園 網站成員  由 昱得資訊工作室 © Since 1993 所提供