ios - How to post both image and text to twitter with SLRequest class on swift? -


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://api.twitter.com/1.1/statuses/update.json")                     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)")                     })                 }             }     })  } 

the problem of code text can posted without image. search lot , try find information on twitter's website. still confused how it. twitter used have api called post statuses/update_with_media job want now. unfortunately twitter discarded api , uses new one. indeed found similar questions mine, of them either uses objective-c or uses old twitter api. nothing helpful me. lot of research consuming me lot of time looks need use addmultipartdata job, don't know how fill these parameters or maybe wrong direction either.

func twitter(){     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"] = self.txtpostdesc.text! //textbox         let imagedata = uiimagepngrepresentation(self.imagepost)//pickerview add         let imagestring = imagedata!.base64encodedstringwithoptions(nsdatabase64encodingoptions())         message["media_ids"] = imagestring         let requesturl = nsurl(string: "https://upload.twitter.com/1/statuses/update_with_media.json")         let postrequest = slrequest(forservicetype: slservicetypetwitter, requestmethod: slrequestmethod.post, url: requesturl, parameters: message)          postrequest.addmultipartdata(imagedata, withname: "media", type: nil, filename: nil)             postrequest.account = twitteraccount              postrequest.performrequestwithhandler({(responsedata: nsdata!,urlresponse: nshttpurlresponse!,error: nserror!) -> void in              if let err = error {                 print("error : \(err.localizeddescription)")             }                 print("twitter http response \(urlresponse.statuscode)")                 self.alertshow("successful")                 })              }         }     })  } 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -