Search code examples
iosswifttwitterphotoswifter

Post a tweet with a photo using the Swifter Framework / Library


I'm using Swifter Library to try to post a tweet with a photo but every time I try, i get an error "The operation couldn’t be completed. (SwifteriOS.SwifterError error 1.)"

My code looks like

var tweetMedia: [String: Any]? //I then set tweetMedia to a UIImageView from the UIImagePickerControllerOriginalImage let picForTwitterApi = tweetMedia![UIImagePickerControllerOriginalImage] as! UIImage let image = UIImagePNGRepresentation(picForTwitterApi) as Data? self.swifter?.postTweet(status: tweetText, media: image!, inReplyToStatusID: nil, coordinate: nil, placeID: nil, displayCoordinates: nil, trimUser: false, tweetMode: TweetMode.default, success: { json in self.alert(title: "Tweet PHOTO sent", message: "👍🏾") }, failure: failureHandler)

But it does not work, i even tried

self.swifter?.postMedia(image!, additionalOwners: nil, success: { json in print(json)

instead, still no success. When I post a regular vanilla tweet like self.swifter?.postTweet(status: tweetText, inReplyToStatusID: nil, trimUser: false, tweetMode: TweetMode.default, success: { json in print(json).....

Everything works perfectly fine, I only have problems when I try to post a photo. Please help. Thanks in advance


Solution

  • I found the solution. The picture must be small. Even smaller than 5mb the documentation suggest. I used an image that was only 100KB and it worked. If I want to post a larger image/video (even just one picture) you have to use the chunked media post ability