func twitterSender(photoImported: NSString) ->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
let message = ["media" : photoImported]
let requestURL = NSURL(string:
"https://upload.twitter.com/1.1/media/upload.json")
let postRequest = SLRequest(forServiceType:
SLServiceTypeTwitter,
requestMethod: SLRequestMethod.POST,
URL: requestURL,
parameters: message)
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)")
})
}
}
})
}
With above code it seems like I can get a successful information since right stuff will be printed, but I check my twitter, nothing is there. Also I only implement upload photo with this code, what should I do if I want to post both photo and text at the same time? Do I still need https://upload.twitter.com/1.1/media/upload.json or https://upload.twitter.com/1.1/status/upload.json? By the way what I have tried to do is that I add a new element in parameters dictionary [“statues” : “my text body”] along with media one. But it doesn’t work at all.