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

人盡茶涼 提交于 2019-12-13 03:42:02

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/49691187/post-a-tweet-with-a-photo-using-the-swifter-framework-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!