Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Twilio SMS消息在控制台应用程序中不工作_C#_Twilio - Fatal编程技术网

C# Twilio SMS消息在控制台应用程序中不工作

C# Twilio SMS消息在控制台应用程序中不工作,c#,twilio,C#,Twilio,我为我的Twilio帐户提供资金,目前正在一个控制台应用程序中工作。当转到文档(此处:)并输入我的电话号码时,请求生效。但是,当我将代码复制到本地控制台应用程序时,什么也没有发生。我逐行复制代码,确保SID、令牌和数字正确无误,并且什么也没发生,控制台应用程序只运行到执行结束 string AccountSid = "MySID"; string AuthToken = "MyAuthToken"; var twilio = new TwilioRestClient(AccountSid, Au

我为我的Twilio帐户提供资金,目前正在一个控制台应用程序中工作。当转到文档(此处:)并输入我的电话号码时,请求生效。但是,当我将代码复制到本地控制台应用程序时,什么也没有发生。我逐行复制代码,确保SID、令牌和数字正确无误,并且什么也没发生,控制台应用程序只运行到执行结束

string AccountSid = "MySID";
string AuthToken = "MyAuthToken";
var twilio = new TwilioRestClient(AccountSid, AuthToken);
var message = twilio.SendSmsMessage("+12222222222", "+13333333333","Hello World");
Console.WriteLine(message.Sid);
我运行Fiddler,我得到这个原始包。Fiddler还说结果是401状态码

POST HTTP/1.1 授权:基本{tonsofRandomCharactersThatLookeIshoulHide} 接受:application/json、application/xml、text/json、text/x-json、text/javascript、text/xml 接受字符集:utf-8 用户代理:twilio csharp/3.4.1.0(.NET 4.0.30319.17929) 内容类型:application/x-www-form-urlencoded 主持人:api.twilio.com 内容长度:56 接受编码:gzip,deflate 连接:保持活力

From=%2B14697891380&To=%2B12146630105&Body=New%20Message

你有什么想法吗?我知道其他人有这个问题,我看到它张贴在其他地方,但我还没有看到回应


这里还有一个链接,指向另一个有此问题的人。我愿意发表评论,但我没有发表评论的名声,因此我在这里又发表了一篇帖子()

Twilio福音传道者

您发布的代码在我看来是正确的,但根据Fiddler的输出,听起来好像您遇到了身份验证错误,因此我将再次检查您是否已从Twilio帐户仪表板正确复制并粘贴了帐户sid和身份验证令牌


希望这能有所帮助。

我无法让Twilio正常工作,这不是技术问题的答案(我想由于某种原因Twilio没有授权我的帐户),但对于那些需要尽快完成原型制作并需要一些东西的人,我最终使用了Plive,并在一小时内收到了一个电话和一条短信。这是我的示例代码,它实际上比Twilio便宜。我真的很喜欢Twilio,过去也用过,但从来没有用过C。也许我还能尽快解决这个问题

using System;
using System.Collections.Generic;
using System.Reflection;
using RestSharp;
using Plivo.API;

namespace Plivo2
{
    class Program
    {
        static void Main(string[] args)
        {

            string auth_id = "MyAuthID";  // obtained from Plivo account dashboard
            string auth_token = "MyAuthTokey";  // obtained from Plivo account dashboard

            // Making a Call
            string from_number = "MyPliveNumber";
            string to_number = "TheNumberYouWantToContact";

            SendMessage(auth_id, auth_token,  from_number,  to_number,"Hello World!");

        }

        private static void CallPhone(string auth_id,string auth_token, string fromNumber, string toNumber){

            // Creating the Plivo Client
            RestAPI plivo = new RestAPI(auth_id, auth_token);

            IRestResponse<Call> response = plivo.make_call(new Dictionary<string, string>() {
                { "from", fromNumber },
                { "to", toNumber }, 
                { "answer_url", "http://some.domain.com/answer/" }, 
                { "answer_method", "GET" }
            });

            // The "Outbound call" API response has four properties -
            // message, request_uuid, error, and api_id.
            // error - contains the error response sent back from the server.
            if (response.Data != null)
            {
                PropertyInfo[] proplist = response.Data.GetType().GetProperties();
                foreach (PropertyInfo property in proplist)
                    Console.WriteLine("{0}: {1}", property.Name, property.GetValue(response.Data, null));
            }
            else
                Console.WriteLine(response.ErrorMessage);

        }

        private static void SendMessage(string auth_id,string auth_token, string fromNumber, string toNumber, string message) { 

            RestAPI plivo = new RestAPI(auth_id, auth_token);

            IRestResponse<MessageResponse> resp = plivo.send_message(new Dictionary<string, string>() 
            {
                { "src", fromNumber },
                { "dst", toNumber },
                { "text", message },
                { "url", "http://some.domain/receivestatus/" },
                { "method", "GET" }
            });
            if (resp.Data != null)
            {
                PropertyInfo[] proplist = resp.Data.GetType().GetProperties();
                foreach (PropertyInfo property in proplist)
                    Console.WriteLine("{0}: {1}", property.Name, property.GetValue(resp.Data, null));
            }
            else
                Console.WriteLine(resp.ErrorMessage);
        }


    }
}
使用系统;
使用System.Collections.Generic;
运用系统反思;
使用RestSharp;
使用Plivo.API;
名称空间Plivo2
{
班级计划
{
静态void Main(字符串[]参数)
{
字符串auth\u id=“MyAuthID”;//从Plivo帐户仪表板获取
字符串auth_token=“MyAuthTokey”;//从Plivo帐户仪表板获取
//打电话
来自_number=“MyPliveNumber”的字符串;
字符串至_number=“TheNumberYouWantToContact”;
SendMessage(auth_id,auth_令牌,from_number,to_number,“Hello World!”);
}
专用静态void CallPhone(字符串身份验证id、字符串身份验证令牌、字符串fromNumber、字符串tonNumber){
//创建Plivo客户端
RestAPI plivo=新的RestAPI(身份验证id、身份验证令牌);
IRestResponse response=plivo.make_call(新字典(){
{“from”,fromNumber},
{“to”,toNumber},
{“答案url”http://some.domain.com/answer/" }, 
{“回答方法”,“获取”}
});
//“出站调用”API响应有四个属性-
//消息、请求id、错误和api id。
//错误-包含从服务器返回的错误响应。
if(response.Data!=null)
{
PropertyInfo[]proplist=response.Data.GetType().GetProperties();
foreach(PropertyInfo属性在proplist中)
WriteLine(“{0}:{1}”,property.Name,property.GetValue(response.Data,null));
}
其他的
Console.WriteLine(response.ErrorMessage);
}
私有静态void SendMessage(字符串auth_id、字符串auth_令牌、字符串fromNumber、字符串tonNumber、字符串消息){
RestAPI plivo=新的RestAPI(身份验证id、身份验证令牌);
IRestResponse resp=plivo.send_消息(新字典()
{
{“src”,fromNumber},
{“dst”,toNumber},
{“文本”,消息},
{“url”http://some.domain/receivestatus/" },
{“方法”,“获取”}
});
如果(响应数据!=null)
{
PropertyInfo[]proplist=resp.Data.GetType().GetProperties();
foreach(PropertyInfo属性在proplist中)
WriteLine(“{0}:{1}”,property.Name,property.GetValue(resp.Data,null));
}
其他的
控制台写入线(相应错误消息);
}
}
}

我在//构建会议上找到了这篇博文。我实现了它,发现HTTP请求中出现了一个401 Not Authorized错误。不确定发生了什么,SID和Auth令牌与文档中基于浏览器的示例一起工作,但当我绕过它们使用Nuget分发的库并使用本文中的示例时,就不起作用了。是的,我已经复制并粘贴正确了。我在想,也许我的帐户还没有被激活,或者什么的。我几天前做的,但是SID和AuthToken仍然在基于浏览器的演示中工作,而不是在本地使用它们时。事实上,我希望您的@devinReader能够回复我,感谢您至少向我保证代码是有效的。现在我知道应该把重点放在SID和令牌上。作为验证点,我假设使用示例中提供的或本页上提供的AccountSID和AuthToken,对吗?您应该在此处或设置页面使用AccountSid和AuthToken。一旦你注册,你就不必做任何其他事情来开始使用你的帐户。我们不会手动授权帐户。如果你仍然有困难,请发一封电子邮件给我devin[at]twilio[dot]com,我可以看看发生了什么