I try to use SLRequest to post both text and meida to twitter. But somehow only text can be posted. I barely find any information that how to use this class. What's more since twitter change its API in terms of posting media all informaiton I can find in the internet dosn't work anymore. I post the same question on twitter's forum but no body answer me. Is there anybody who can help me.
func twitterSender(photoImported: UIImage) ->Void {
let account = ACAccountStore()
let accountType = account.accountTypeWithAccountTypeIdentifier(
ACAccountTypeIdentifierTwitter)
account.requestAccessToAccountsWithType(accountType, options: nil,
completion: {(success: Bool, error: NSError!) -> Void in
if success {
let arrayOfAccounts =
account.accountsWithAccountType(accountType)
if arrayOfAccounts.count > 0 {
let twitterAccount = arrayOfAccounts.last as! ACAccount
var message = Dictionary<String, AnyObject>()
message["status"] = "My app test 5"
let imageData = UIImageJPEGRepresentation(photoImported, 0.9)
let imageString = imageData.base64EncodedStringWithOptions(NSDataBase64EncodingOptions.allZeros)
message["media_ids"] = imageString
let requestURL = NSURL(string:
"https:/
let postRequest = SLRequest(forServiceType:
SLServiceTypeTwitter,
requestMethod: SLRequestMethod.POST,
URL: requestURL,
parameters: message)
postRequest.addMultipartData(imageData, withName: "oauth_*", type: "application/octet-stream", filename: "image.jpg")
postRequest.account = twitterAccount
postRequest.performRequestWithHandler({
(responseData: NSData!,
urlResponse: NSHTTPURLResponse!,
error: NSError!) -> Void in
if let err = error {
println("Error : \(err.localizedDescription)")
}
println("Twitter HTTP response \(urlResponse.statusCode)")
})
}
}
})
}