In my app the user should upload a picture to Twitter (with the Rest API). Now the user can only tweet with text but this works with this code:
let textToTweet = textView.text
let url = NSURL(string: "https://api.twitter.com/1.1/statuses/update.json")
let request = SLRequest(forServiceType: SLServiceTypeTwitter, requestMethod: .POST, URL: url, parameters: ["status": textToTweet!])
request.account = twitterAccount
request.performRequestWithHandler { (data, response, error) -> Void in
if response.statusCode != 200 {
print("not working")
}
}
Now I wanted to take a step forward and used this, but it´s not working with this code. :
let textToTweet = textView.text
let imageToTweet = image.image
let url = NSURL(string: "https://api.twitter.com/1.1/statuses/update_with_media.json")
let request = SLRequest(forServiceType: SLServiceTypeTwitter, requestMethod: .POST, URL: url, parameters: ["status": textToTweet!, "media[]": imageToTweet!])
request.account = twitterAccount
request.performRequestWithHandler { (data, response, error) -> Void in
if response.statusCode != 200 {
print(error)
}
}
Here´s the information that gives Twitter about POST statuses/update_with_media. The console is showing "fatal error: unexpectedly found nil while unwrapping an Optional value" and the app isn´t posting the post or the image. Thank you!