Twilio Client c# - 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?

Related

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.

Android - Refit throws UnknownHostException unexpectedly

I'm trying to implement Refit using Xamarin and for some reason it throws a UnknownHostException (UHExc) if I was previously not connected to wifi while the app was open. This doesn't happen consistently though.
I have these two calls to Refit's instantiation of my "Refit-interface": PostLoginAsync and GetDataAsync, as shown below (the guide I've been following is here):
public async Task<SomeClass> PostLogin(string user, string password)
{
SomeClass response = null;
var loginTask = apiService.UserInitiated.PostLoginAsync(new RequestBody(user: user, password: password));
response = await FireWebTask(loginTask);
return response;
}
and
private async Task<List<Data>> GetRemoteDataAsync(string args)
{
List<Data> list = null;
var getDataTask = apiService.UserInitiated.GetDataAsync(args);
list = await FireWebTask(getDataTask);
return list;
}
The "Refit-interface" looks somewhat like this:
...
[Post("/relative/url/to/login")]
Task<SomeClass> PostLoginAsync([Body(BodySerializationMethod.Json)] RequestBody requestBody);
[Get("/relative/url/to/data")]
Task<List<Data>> GetDataAsync([Header("SomeHeader")] string args);
...
When I open the app with no connection to the internet and try to send the PostLogin-request, I get an UHExc as expected. If I then turn on the wifi and try again (without closing the app) I get the UHExc again, only this time with almost no delay as the first time (as if the exception was cached??). Restarting the app and trying again without disconnecting the wifi works fine.
If I do the exact same thing with the second request (GetData) I first get an UHExc (obviously) but when reconnecting the wifi it works flawlessly. So it seems to me like the POST-request caches the exception or something and throws it repeatedly without trying to connect at all. How can I solve this (whatever the problem actually is)?
I also had this problem and after some testing discovered that the issue is with the Fusillade library. Now the initial problem is that the fixing changes are not reflected in the NuGet packages so you need to download the latest source from the Github repo and reference the newer dlls.
Looks like the underlying issue is due to the failed requests getting enqueued and played back even though the request resulted in a WebException.
I included the latest code into my project and confirmed that they are working.

Twilio not sending SMS

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:

Error in EmailMessage.Forward (EWS) method.

I'm using EWS to read a mailbox and based on a certain conditions, forward the emails out to a set of users. However, the process fails with this error:
"An internal server error occurred. The operation failed."
and this:
"An unhandled exception of type 'Microsoft.Exchange.WebServices.Data.ServiceResponseException' occurred in Microsoft.Exchange.WebServices.dll"
Here's my sample code:
EmailAddress[] emailids = new EmailAddress[4];
emailids[0] = new EmailAddress("user1#domain.com");
emailids[1] = new EmailAddress("user2#domain.com");
msg.Forward("This message was Auto forwarded", emailids);
The msg is an object of type EmailMessage in Microsoft.Exchange.WebServices.Data;
Any help would be appreciated.
Thank you
Abhi
In your code you've defined an array of 4 EmailAddress but you are only using 2 which would cause issues.
Does this fail on every message you try to forward or just certain messages or are you forwarding as batch and fails after a certain number.
There are Throttling restrictions with Exchange http://msdn.microsoft.com/en-us/library/office/jj945066(v=exchg.150).aspx that can affect a number of things one of those in the recipient limits eg RecipientRateLimit and ForwardeeLimit.
You might also want to enable tracing http://msdn.microsoft.com/en-us/library/office/dd633676(v=exchg.80).aspx and post the full response you get
Cheers
Glen

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