I want to post a photo to twitter from my iOS app. I can post a tweet without media but when i am trying to attach media it throws an error.
I am following twitter docu
Sharing the swift 2.2 (Xcoe 7.3.2) code if anyone is still looking for help.
let client = TWTRAPIClient.init(userID:)
let imgData = UIImageJPEGRepresentation(UIImage(named:"Home")!, 0.7)
client.uploadMedia(imgData!, contentType: "image/jpeg", completion: {(media_ids,error) in
if error == nil{
//prints the media_ids in String.
//Pass them into the params of status update params ["media_ids":]
print(media_ids)
}
else{
print(error?.localizedDescription)
}
})
To Send with status update.
let request = client.URLRequestWithMethod("POST", URL: "https://api.twitter.com/1.1/statuses/update.json", parameters: ["status":"Hello World","media_ids":], error: nil)
client.sendTwitterRequest(request, completion: {
(response,data,error)in
if error == nil {
print(data)
}
else{
print("Error")
}
})
}