I am trying to post an image and tweet using Twitters new TwitterKit with a custom UI. The only documentation they provide is how to do it with their views.
so I can figure out how to do it without an image
NSMutableDictionary *message = [[NSMutableDictionary alloc] initWithObjectsAndKeys:[params objectForKey:@"description"],@"status",@"true",@"wrap_links", nil];
NSURLRequest* request = [twAPIClient URLRequestWithMethod:@"POST" URL:@"https://api.twitter.com/1.1/statuses/update.json" parameters:message error:nil];
[twAPIClient sendTwitterRequest:request completion:^(NSURLResponse* response, NSData* data, NSError* connectionError){
}];
But their URLRequestWithMethod method isnt mutable. how would I add an image to it. You used to do it with the SLRequest with
[postRequest addMultipartData:UIImageJPEGRepresentation(image, 0.5) withName:@"media" type:@"image/jpeg" filename:@"image.png"];
As of about April 2016, Fabric's TwitterKit 2.0 (or newer) exposes a new method
uploadMedia
to cover the media uploading part. Here is some objc code that works for me.Swift
I Have figured it out.
First you need to post the image to twitter.
then in the response object you use the media_id_string and add that to the parameter of the code in my question.
So
note the media_ids object that is from the response of the first request
So you can just put that inside the completion block and it will post the image and tweet.
Swift 4 latest
1) Check login is done or not
2) To upload image with text
Note : install pod file pod 'TwitterKit'. You need to setup other minor things related to login in appdelegate and URL Schemes(above code is related to login and post image with text)
import TwitterKit