Skip to content

Instantly share code, notes, and snippets.

@martinbowling
Forked from Clancey/gist:2357027
Created April 11, 2012 05:42
Show Gist options
  • Save martinbowling/2357245 to your computer and use it in GitHub Desktop.
Save martinbowling/2357245 to your computer and use it in GitHub Desktop.
public void sendTweet(string updateText)
{
ACAccountStore account = new ACAccountStore();
var accountType = account.FindAccountType(ACAccountType.Twitter);
account.RequestAccess(accountType,(granted,NSError)=> {
if(!granted)
return;
var arrayOfAccounts = account.FindAccounts(accountType);
if(arrayOfAccounts != null && arrayOfAccounts.Length == 0)
return;
TWRequest postRequest = new TWRequest ( new NSUrl (@"http://api.twitter.com/1/statuses/update.json"), NSDictionary.FromObjectAndKey (NSObject.FromObject (updateText.ToString() + "\r\n"), NSObject.FromObject ("status")), TWRequestMethod.Post);
postRequest.Account = arrayOfAccounts[0];
postRequest.PerformRequest ((responseData, urlResponse, error) =>{
InvokeOnMainThread (() =>{
if(urlResponse.StatusCode == 200){
new UIAlertView("Success", "Tweet Posted \n" + responseData.ToString (),null,"Ok",null).Show ();
}
else {
new UIAlertView("Oh Noes!", "Error \n" + error.ToString(),null,"Ok",null).Show ();
}
}
);
} );
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment