Domanda

I funded my Twilio account and am working in a console application. When to go to the documentation (Here: https://www.twilio.com/user/account/developer-tools/api-explorer/message-create) and enter my phone number the request works. However, when I copy the code to a local console application nothing happens. I literally copy the code line for line and make sure the SID, Token, and Numbers are correct and nothing happens at all, the console app just runs to the end of execution.

string AccountSid = "MySID";
string AuthToken = "MyAuthToken";
var twilio = new TwilioRestClient(AccountSid, AuthToken);
var message = twilio.SendSmsMessage("+12222222222", "+13333333333","Hello World");
Console.WriteLine(message.Sid);

I run Fiddler and I get this for the Raw Packet. Also Fiddler says the result is a 401 status code.

POST https://api.twilio.com/2010-04-01/Accounts/MySID/SMS/Messages.json HTTP/1.1 Authorization: Basic {TonsOfRandomCharactersThatLookLikeISHouldHide} Accept: application/json, application/xml, text/json, text/x-json, text/javascript, text/xml Accept-charset: utf-8 User-Agent: twilio-csharp/3.4.1.0 (.NET 4.0.30319.17929) Content-Type: application/x-www-form-urlencoded Host: api.twilio.com Content-Length: 56 Accept-Encoding: gzip, deflate Connection: Keep-Alive

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

Any ideas on what could be going one? I know others are having this issue, I see it posted in other places, but I have yet to see a response.

Also here is a link to another person having this issue. I would comment, but I do not have the reputation to enter a comment, hence why I made another thread (Why is Twilio not sending sms?)

È stato utile?

Soluzione

I was unable to get Twilio to work, this is not the answer to the technical issues (I think for some reason Twilio just has not authorized my account), but for those of you prototyping and need something asap I ended up using Plive and has a call and text message working within an hour. Here is my Sample code and it is actually cheaper than Twilio. I really like Twilio and have used it in the past, but never with C#. So maybe I can still get the issue resolved asap.

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);
        }


    }
}

Altri suggerimenti

Twilio evangelist here.

The code you posted looks correct to me, but based on the Fiddler output it sounds like your getting an authentication error so I would double check that you've copy and pasted your account sid and auth token from your Twilio account dashboard correctly.

Hope that helps.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top