如何使用C#和twilio API发送短信

nap*_*i15 3 c# sms visual-studio twilio twilio-api

我正在尝试创建一个用户界面,用户可以在其中输入她的凭证和电话号码,并使用Twilio API向某些收件人发送消息

因此,我解释说,我创建了我的帐户并初始化了身份验证密钥和令牌

    private void button1_Click(object sender, EventArgs e)
    {
         string ssid = twilioSSIDBox.Text;
         string token = twilioTokenBox.Text;
         string number = twilioNumberBox.Text;


        var client = new TwilioRestClient(Environment.GetEnvironmentVariable(ssid), Environment.GetEnvironmentVariable(token));
        client.SendMessage(number, "+158965220", "Teting API message!");

    }
Run Code Online (Sandbox Code Playgroud)

经过多次测试(硬编码ssid和令牌和编号)和文档咨询后,仍未在visual studio平台上发送消息,我没有收到任何错误消息或任何内容

所以我的问题是我错过了什么?我是否需要某个允许visual studio能够发送短信的库?

我正在使用Visual Studio 2015和Windows 10平台

谢谢

nap*_*i15 5

我最终解决了我的问题

所以这不适用于VS2015平台:

    var client = new TwilioRestClient(Environment.GetEnvironmentVariable(ssid), Environment.GetEnvironmentVariable(token));
    client.SendMessage(number, "+158965220", "Teting API message!");
Run Code Online (Sandbox Code Playgroud)

甚至以为我已经使用nuget console安装了Twilio api版本4.7.2

我又做了以下几点:

Install-Package Twilio
Run Code Online (Sandbox Code Playgroud)

比Visual Studio建议我在代码中添加对API的引用

 using Twilio;
using Twilio.Rest.Api.V2010.Account;
using Twilio.Types;
Run Code Online (Sandbox Code Playgroud)

感谢以下示例

这有效:

 TwilioClient.Init(accountSid, authToken);

        var message = MessageResource.Create(
            to: new PhoneNumber(toNumber),
            from: new PhoneNumber(FromNumber),
            body: "Hello from C#");
Run Code Online (Sandbox Code Playgroud)

所以我的结论可能是一个过时的库,因为当我使用NUGET安装时:

Install-Package Twilio -Version 4.7.2
Run Code Online (Sandbox Code Playgroud)

我不知道它为什么不起作用

PS:我不确定它是否相关,但是我也使用NUGET控制台安装了它,它的迁移帮助或者可能没有,但我觉得我必须提到它:

Install-Package RestSharp 
Run Code Online (Sandbox Code Playgroud)