Twilio not sending SMS - c#

I've tried this code
string AccountSid = "[mySID]";
string AuthToken = "[myAuthCode]";
var twilio = new TwilioRestClient(AccountSid, AuthToken);
var me = twilio.SendMessage("+15016536555", "+923355216606", "A blank txt");
Console.WriteLine(me.Sid);
I put my original SID and AuthToken in my code. The me.Sid is giving null.
Moreover, the To number is also registered.
I noted that the To and From in me variable is empty.Their is only send and recieve date and time.

I tried your code and it worked fine when To and From numbers were valid. I could receive the text. However, when I changed the From number it failed and reproduced the same problem. It didn't throw an exception, just failed silently.
Interesting thing is there is a RestException property in the message object which displayed "The From phone number +xxxxxxxxxx is not a valid, SMS-capable inbound phone number or short code for your account." This way it was easy to identify the problem.
I installed Twilio wrapper from NuGet
Install-Package Twilio
and the version I've just tried is 4.0.3
If your version is out of date, update it to the latest version so you can check the error using RestException property.
UPDATE:
The message object and RestException in my application looks like this:

Related

Twilio Client c#

I have been using this code to send sms and voice calls for the last few days and now I am getting a weird response. On my recording status app I get the error: The remote name could not be resolved: 'api.twilio.com'. I have stripped down my function to a couple basic lines of code and still get the error.
TwilioClient.Init(_Twilio.ApiSid, _Twilio.ApiToken);
CallResource call = CallResource.Fetch(pathSid: sCallSid);
if (call != null)
{/*handle error*/}
The sCallSid string is valid and has a value. the ApiSid and ApiToken are working as well.
The 'api.twilio.com' resolved statement has stumped.
Any ideas how to isolate this issue and resolve it?

How can I decode Unity's iOS device Token for Push Notifications?

I'm implementing Unity's Notification Service for iOS.
I don't believe I have a problem with my implementation.
This is how I'm Registering:
NotificationServices.RegisterForNotifications(NotificationType.Badge |
NotificationType.Alert | NotificationType.Sound, true);
I also have Push Notifications enabled in my capabilities.
For getting the device token I use NotificationServices.deviceToken.
The problem with DeviceToken is that it returns a byte[] and I don't know how to decode it.
I have tried with several methods, but the only one that gives me something readable is the following:
byte[] token = NotificationServices.deviceToken;
Debug.Log(System.BitConverter.ToString(token).Replace("-", ""));
Debug.Log(Convert.ToBase64String(token));
The first method returns me: 348CDFAE308F9107A3DB0807CC363BBB01DEC33008E9F474A9A81D57D039D245, which, without the replace it would be 34-8C-DF-AE-30-8F-91-07-A3-DB-08-07-CC-36-3B-BB-01-DE-C3-30-08-E9-F4-74-A9-A8-1D-57-D0-39-D2-45
The second methods returns me: cFXd3wLN0aCOpx7vn9pwDlJ24W32m9WO3A+WY28G4Zs=
BUT, and here is the interesting part, if I modify the method that Unity generates when compiling didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken, with the following example:
NSString *token;
token = [deviceToken description];
NSLog(#"Token: %#", token);
I get the following result:
Token: <7055dddf 02cdd1a0 8ea71eef 9fda700e 5956e16d 8e9bd54e dc0f9263 6f03e19b>
I have tried to send push notifications with all the tokens I have, but none of them work.
So, my question is, from Unity, how can I correctly decode the deviceToken for sending push notifications?
Thanks =)
I found that is with the first method:
byte[] token = NotificationServices.deviceToken;
return BitConverter.ToString(token).Replace("-", "");
Unity gives me everything in capital letters, but it worked while trying push notifications(it looks like iOS doesn't discriminate capital letters). I was making an error by trying to test the development build with a production notification.

No verification code while registering number via message using twilio trial

Hi I am on trial with twilio.
I have seen this link:
https://www.twilio.com/help/faq/twilio-basics/how-does-twilios-free-trial-work
It says "You must verify a phone number before you can send SMS messages to it from your trial phone number."
And also restricts on the outgoing text
But what if I just want to verfiy the number, using:
var twilio = new TwilioRestClient(
Keys.TwilioSid,
Keys.TwilioToken
);
var result = twilio.SendMessage(
Keys.FromPhone,
message.Destination, message.Body);
// Status is one of Queued, Sending, Sent, Failed or null if the number is not valid
Trace.TraceInformation(result.Status);
// Plug in your SMS service here to send a text message.
return Task.FromResult(0);
I get null when I try to verify the number that are not in the dashboard(web twilio) whereas those with verified from dashboard gets the verification from above code.
Is it intended? I think we need to be able to register at least from web interface?
Error: Account not authorized to call . Perhaps you need to enable some international permissions: twilio.com/user/account/settings/international For Message The number XX is unverified. Trial accounts cannot send messages to unverified numbers; verify xxx at twilio.com/user/account/phone-numbers/verified, or purchase a Twilio number to send messages to unverified numbers
I don't think you can verify a number in the way that you are attempting to do it. Verifying a number adds it to your outgoing numbers. you can look at this page, which provides the full details. https://www.twilio.com/docs/api/rest/outgoing-caller-ids#list-post-example-1
A snippet from the page using the C# Api,
// Find your Account Sid and Auth Token at twilio.com/user/account
string AccountSid = "{{ sid }}";
string AuthToken = "{{ auth_token }}";
var twilio = new TwilioRestClient(AccountSid, AuthToken);
var callerId = twilio.AddOutgoingCallerId("+14158675309", "My Home Phone Number", null, null);
Console.WriteLine(callerId.ValidationCode);
The first argument is the number you would like to verify, and the second argument is simply a friendly name for the number. The above process will initiate a call to the number and ask you to provide the validation code. You will then use the value that is printed to the console and enter that during the validation process, provided that all goes well, once the above process is complete, the number would be verified and you will be able to send an Sms to that number.
Twilio evangelist here.
A trial account has a number of restrictions placed on it, including you can only send SMS messages to verified phone numbers. A verified phone number will show up in your Twilio dashboard under Numbers > Verified Caller IDs:
https://www.twilio.com/user/account/phone-numbers/verified
To verify a number using the .NET helper library, call the AddOutgoingCallerId method like Lewis showed.
Calling this method returns to you a six digit verification code. Twilio will then call the number that you want to verify and ask the person who answers to enter that 6 digit code. If the code entered matches, Twilio adds that phone number as a Verified Caller ID and you an send text messages to it.
Note that while using a Trial account, messages will also be prefixed with the message "Sent from a Twilio Trial account".
If the request to the Twilio REST API made by the AddOutgoingCallerId method fails (wrong credentials, invalid method parameters, etc), you determine this by checking the RestException property:
var result = twilio.AddOutgoingCallerId("+15555555555","Verified Number",null,null);
if (result.RestException!=null) {
Debug.Writeline(result.RestException.Message);
}
Hope that helps.

Twilio Test Credentials: WaitingForActivation when I try to purchase a number?

I have the following code:
public void PurchaseNumber(string username, string phoneNumber) {
var twilio = new TwilioRestClient(accountSid, authToken);
var options = new PhoneNumberOptions {
VoiceUrl = "",
PhoneNumber = "+15005550006"
};
var number = twilio.AddIncomingPhoneNumber(options);
Console.WriteLine(number.Id); // Sid is not available
return;
}
Two issues - number.Sid is not available, as the samples display, and number.Status always shows "WaitingForActivation". What am I doing wrong?
Update: This also happens with the 'unavailable' number, not just with the 'valid and available' one. Is the usage of magic numbers available to trial accounts? I am using the SID and Token from the https://www.twilio.com/user/account/developer-tools/test-credentials page.
This also happens if I change one of the characters of my SID - so it seems that my SID is invalid, despite grabbing it directly off of my /developer-tools page.
Final Update - it was because I was using the PreRelease version of the Twilio nuget package. I uninstalled it and installed the non-prerelease version and Sid became available and everything started working.
Final Update - it was because I was using the PreRelease version of the Twilio nuget package. I uninstalled it and installed the non-prerelease version and Sid became available and everything started working.

Twitterizer: "Could not authenticate with OAuth"

I'm using Twitterizer library for posting tweets within a web-site into my twitter account. It works just fine on site, running on my local server (authenticates with OAuth through twitter app and posts a tweet).
But when I'm trying to post a tweet on production server, Twitterizer says: "Result = Unauthorized. ErrorMessage = Could not authenticate with OAuth."
I double checked consumer keys, also tried to reset the keys and try again - same result.
Twitter application has read/write access to my twitter account and is not blocked.
This problem appeared suddenly after a period of successful working for about a month, when tweets were posted every hour or so.
What is the problem here?
UPDATE
It seems, that other guys also face this problem: https://dev.twitter.com/discussions/305
UPDATE 2
Finally, I have found out what caused the problem to appear in my case. Web app on production server tried to update a status with 140 characters (measured by String.Length property). And the first character was unicode Character 'LEFT-TO-RIGHT MARK' (U+200E). So, this text was passed to TwitterStatus.Update(..) without changes. I debugged a bit Twitterizer sources and noticed that oauth_signature(=hash) was calculated incorrectly. oauth_signature was generated from another url that was actually requested. I haven't cleared the reason why and when this error occurs and maybe will write more information in next few days.
UPDATE 3
I tried to post the same message with new version of Twitterizer (2.3.3) and no error occured. Problem disappeared.
It's the code, that I'm using to post a tweet:
OAuthTokens tokens = new OAuthTokens();
tokens.AccessToken = ConfigurationManager.AppSettings["twitterAccessToken"];
tokens.AccessTokenSecret = ConfigurationManager.AppSettings["twitterAccessTokenSecret"];
tokens.ConsumerKey = ConfigurationManager.AppSettings["twitterAutoPosterConsumerKey"];
tokens.ConsumerSecret = ConfigurationManager.AppSettings["twitterAutoPosterConsumerSecret"];
string text = "Some text";
TwitterResponse<TwitterStatus> tweetResponse = TwitterStatus.Update(tokens, text);
if (tweetResponse.Result == RequestResult.Success)
{
// Tweet posted successfully!
_log.InfoFormat("Posted a tweet #{0}.", tweetResponse.ResponseObject.Id);
}
else
{
_log.ErrorFormat("Error occured while posting a tweet. Result = {0}. ErrorMessage = {1}",
tweetResponse.Result, tweetResponse.ErrorMessage);
}
Please check in the message, if message have apostrophes (') , please replace it with &#39;
Note that &#39; will count as 5characters.
I think that apostrophes will effect the request package that send to twitter, that make twitter cannot get Token Correctly, so we will got error "Could not authenticate with OAuth".
I had the same trouble. PHP 5.3.1 ran on my local server, while PHP 4.3.2 ran on my production server. I use OAuth library of Google Code obtained from the below,
http://code.google.com/p/oauth/source/browse/#svn%2Fcode%2Fjavascript.
I explored the OAuth header which PHP proxy program received from javascript code on a browser. On my local server, it was
OAuth realm="",oauth_consumer_key="XXX",oauth_token="XXX",oauth_version="1.0",oauth_timestamp="1314956434",oauth_nonce="mF7Tof",oauth_signature_method="HMAC-SHA1",oauth_signature="DbuaiDeMhMYNZ5BaQmOoFr%2FRsEQ%3D"
while on my production server, all the double quotations above were escaped, namely, '\"'.
So I replaced the escaped double quotation to the unescaped one using str_replace function. Then it got work well just the same on my production server. The cause is the difference of the way how double quotation is treated between PHP 5.3.1 and PHP 4.3.2. Escaped double quotation caused an error "Could not authenticate with OAuth."

Categories