如何使用 Excel VBA 将桌面照片发送到电报 [英] How to send a desktop photo to telegram using Excel VBA

查看:73
本文介绍了如何使用 Excel VBA 将桌面照片发送到电报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我需要支持来使用示例或确切的代码来做这件事,因为我迷路了并且对发送一无所知

Greeting, I need support to do this with example or exact code as I'm lost and don't know a bit about sending

Function VBA2Telegram(token As String, ChatID As String)
Dim msg1 As String, PostMsgStr As String, PhotoPath As String,sUrl As String
Dim oHttp As Object, sHTML As String, PostPhotoStr As String, strPostData As String

msg1 = "Hello there"
PhotoPath = "C:\1123.jpg"
PostMsgStr = "https://api.telegram.org/bot" & token & "/sendMessage?chat_id=" & ChatID & "&text=" & msg1
PostPhotoStr = "https://api.telegram.org/bot" & token & "/sendPhoto?chat_id=" & ChatID & "&photo=" & PhotoPath

Set oHttp = CreateObject("MSXML2.XMLHTTP")

oHttp.Open "POST", PostMsgStr, False
oHttp.Send

'Here,, how to set the code to do the job of sending local photo to telegram!
oHttp.Open "POST", PostPhotoStr, False
oHttp.Send

sHTML = oHttp.ResponseText
Debug.Print sHTML

End Function

推荐答案

要上传您机器中的照片,您不能对带有文件路径的请求使用 GET 方法,而应在文件内容的 multipart/form-data 样式:请参阅文档.

To upload a photo which is in your machine, you cannot use the GET method for the request with the path of your file, instead you should POST a form in multipart/form-data fashion with the content of the file: see the documentation.

您可以搜索如何在 vba 中使用 multipart/form-data.这个链接堆栈溢出答案也可能对您有所帮助.

You can search how to use multipart/form-data in vba. This link or stack overflow answer may help you as well.

这篇关于如何使用 Excel VBA 将桌面照片发送到电报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆