Instantly share code, notes, and snippets.

Embed
What would you like to do?
Post Image and Tweet
public void PostImageAndTweetToTwitter()
{
if (SLComposeViewController.IsAvailable (SLServiceKind.Twitter)) {
var post = new NSString("Testing Social Framework!");
var twitterRequest = SLRequest.Create(SLServiceKind.Twitter,
SLRequestMethod.Post,
NSUrl.FromString("https://upload.twitter.com/1/statuses/update_with_media.json"),
NSDictionary.FromObjectAndKey(post, new NSString("status"))
);
var image = UIImage.FromFile("monkey.png");
twitterRequest.AddMultipartData(image.AsPNG(),"media[]","image/png","monkey.png");
var accountStore = new ACAccountStore();
var accountType = accountStore.FindAccountType(ACAccountType.Twitter);
accountStore.RequestAccess(accountType, null, (granted, error) => {
if(granted)
{
var account = accountStore.FindAccounts(accountType).First();
twitterRequest.Account = account;
twitterRequest.PerformRequest((data, response, e) => {
if(response.StatusCode == 200) {
Console.WriteLine(data.ToString());
} else {
Console.WriteLine("Error {0}", response.StatusCode.ToString());
}
});
}
});
} else {
resultsTextView.Text = "Twitter Account not added";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment