0

我需要使用 Twilio 和 Microsoft Access 在文本消息中从我的电脑发送图像。

我能够通过 Microsoft Access 成功发送短信。但是,图像没有发送。我找到了一个名为“mediaURL”的参数。我试图让 mediaURL 引用我电脑上的图像(“d:\imagefolder”)。

有没有人能够做到这一点。这是我发送短信的代码。

Dim MessageUrl As String
    Dim FromURLEncode As String
    Dim ToURLEncode As String
    Dim imageURL As String

    On Error GoTo Error_Handler

    ' setup the URL
    MessageUrl = BASEURL & "/2010-04-01/Accounts/" & ACCOUNTSID & "/Messages"
    imageURL = "d:\imagefolder\mypicture.png"

    ' setup the request and authorization
    Dim http As MSXML2.XMLHTTP60
    Set http = New MSXML2.XMLHTTP60

    http.Open "POST", MessageUrl, False, ACCOUNTSID, AUTHTOKEN
    http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"

    Dim postData As String
    postData = "From=" & fromNumber _
                & "&To=" & toNumber _
                & "&Body=" & body _
                & "&MediaURL=" & imageURL

    Debug.Print postData

    ' send the POST data
    http.send postData

    ' optionally write out the response if you need to check if it worked
    Debug.Print http.responseText

    If http.Status = 201 Then

    ElseIf http.Status = 400 Then
        MsgBox "Failed with error# " & _
            http.Status & _
            " " & http.statusText & vbCrLf & vbCrLf & _
            http.responseText
    ElseIf http.Status = 401 Then
        MsgBox "Failed with error# " & http.Status & _
            " " & http.statusText & vbCrLf & vbCrLf
    Else
        MsgBox "Failed with error# " & http.Status & _
            " " & http.statusText
    End If

Exit_Procedure:

    On Error Resume Next

    ' clean up
    Set http = Nothing

Exit Function

Error_Handler:

    Select Case Err.Number

        Case NOINTERNETAVAILABLE
            MsgBox "Connection to the internet cannot be made or " & _
                "Twilio website address is wrong"

        Case Else
            MsgBox "Error: " & Err.Number & "; Description: " & Err.Description

            Resume Exit_Procedure

        Resume

    End Select
4

2 回答 2

2

我终于能够使用 MediaUrl 发送带有图像的文本消息。我的代码使用的是 MediaURL。它必须完全是“MediaUrl”。有一次,我想通了,我已经能够发送带有图像的短信了。

于 2016-06-08T04:36:48.700 回答
1

Twilio 开发人员布道者在这里。

正如 Thomas G 在评论中回答的那样,您的问题是图像在您的计算机上。该 URL 需要对 Twilio 可用。

您需要将图像上传到您自己或公共服务的服务器,然后使用该服务器。

查看有关使用 Twilio 发送彩信的文档以获取更多详细信息

于 2016-05-26T20:50:35.613 回答