Created
March 4, 2014 04:50
-
-
Save therealjohn/9340477 to your computer and use it in GitHub Desktop.
Post Image and Tweet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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