Skip to content

Instantly share code, notes, and snippets.

@therealjohn
Created March 4, 2014 04:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save therealjohn/9340477 to your computer and use it in GitHub Desktop.
Save therealjohn/9340477 to your computer and use it in GitHub Desktop.
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