简体   繁体   中英

twilio nuget package not sending SMS message in vb.net

Does the twilio asp.net helper library package NOT work in vb.net? I can get it to work in c# web app but not vb.net web app.

In a vb.net web application project the following code doesnt send an sms message and when stepping through with the debugger, errs on the send message line and brings up a file dialog asking for access to core.cs. The twilio library's were installed via nuget.

 Public Shared Sub SendAuthCodeViaSms(ByVal number As String)
        Dim twilioAccountInfo As Dictionary(Of String, String) = XmlParse.GetAccountInfoFromXmlFile("twilio")
        Dim accountSid As String = twilioAccountInfo("username")
        Dim authToken As String = twilioAccountInfo("password")
        If (Not String.IsNullOrEmpty(accountSid) AndAlso Not String.IsNullOrEmpty(authToken)) Then
            Dim client = New TwilioRestClient(accountSid, authToken)
            client.SendMessage(TwilioSendNumber, ToNumber, "Testmessage from My Twilio number")
        Else
            'log error and alert developer
        End If

    End Sub

But in a C# web API project the same code sends the message as expected.

 protected void Page_Load(object sender, EventArgs e)
    {
        const string AccountSid = "mysid";
        const string AuthToken = "mytoken";

var twilio = new TwilioRestClient(AccountSid, AuthToken);
        var message = twilio.SendMessage(TwilioSendNumber,ToNumber,"text message from twilio");
    }

and all the sid's and tokens and phone number formats are correct, otherwise the c# one wouldnt send and I wouldnt get to the client.SendMessage part of vb.net version (client.SendSMSMessage produces the same result)

Twilio evangelist here.

I tried our your code by creating a simple VB console app and it worked for me.

The only thing I can think of is that either you are not getting your Twilio credentials correctly when parsing the XML, or the phone number you are passing into the function is not formatted correctly.

I'd suggest putting the result of call to SendMessage() into a variable and checking to see if RestException property is null:

Dim result = client.SendMessage(TwilioSendNumber, ToNumber, "Testmessage from My Twilio number")
If (Not IsNothing(result.RestException)) Then
   ' Something bad happened
Endif

If Twilio returns a status code greater than 400, then that will show up as an exception in the RestException property and will give you a clue as to whats going on.

If that does not work, you can always break out a tool like Fiddler to watch and see if the library is making the property HTTP request and Twilio is returning the proper result.

Hope that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM