【问题标题】:Twilio TwilioRestClient does not contain a definition for SendSmsMessageTwilio TwilioRestClient 不包含 SendSmsMessage 的定义
【发布时间】:2017-04-29 05:39:17
【问题描述】:

我正在尝试在我的应用程序中为 SMS 提供程序添加 Twilio,但我在此行收到以下错误:

SendSmsMessage =>
twilio.**SendSmsMessage**(Keys.SMSAccountFrom, message.Destination, message.Body);

TwilioRestClient 不包含 SenSmsMessage 和 没有扩展方法 SenSmsMessage 接受类型的第一个参数 可以找到 TwilioRestClient(您是否缺少 using 指令或 程序集参考?)

我正在开发 Visual Studio 2017、C#、Mvc 5,已安装 Twilio 5.4.0 和 Twilio.Asp.Mvc 5.1

你能帮忙吗?

【问题讨论】:

    标签: c# asp.net asp.net-mvc twilio


    【解决方案1】:

    这里是 Twilio 开发者宣传员。

    您说您安装了Twilio C# library 的5.4.0 版。但是我认为您正在查看版本 4.x 文档,因为 SendSmsMessage 是一种旧方法。

    您现在需要使用新的MessageResource 对象。请查看下面的示例或sending messages here 的文档。

    using System;
    using System.Threading.Tasks;
    using Twilio;
    using Twilio.Rest.Api.V2010.Account;
    using Twilio.Types;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                // Your Account SID from twilio.com/console
                var accountSid = "AC81ebfe1c0b5c6769aa5d746121284056";
                // Your Auth Token from twilio.com/console
                var authToken = "auth_token";   
    
                TwilioClient.Init(accountSid, authToken);
    
                var message = MessageResource.Create(
                    to: new PhoneNumber("+15558675309"),
                    from: new PhoneNumber("+15017250604"),
                    body: "Hello from C#");
    
                Console.WriteLine(message.Sid);
                Console.Write("Press any key to continue.");
                Console.ReadKey();
            }
        }
    }
    

    Twilio.Asp.Mvc 5.1 的版本约束可能不正确,需要版本 4 库。因此,您可能只需将 Twilio 固定回版本 4.7.2,它就会重新开始工作。

    让我知道这是否有帮助。

    【讨论】:

      【解决方案2】:

      假设您的错误消息是从原件复制并粘贴的,那么它看起来像是方法名称中的一个简单拼写错误:您有“SenSmsMessage”,缺少“发送”中的“d”。

      【讨论】:

      • 感谢Daniel Hume的回复,错误信息不是复制粘贴,我必须输入,没有注意到错字。
      猜你喜欢
      • 2013-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多