2
任何人都可以請告訴我如何使用Twitterkit
或任何其他編程方式在(swift或objective-c)中發佈視頻Twitter
。我看過很多與此相關的帖子,但沒有找到任何解決方案。我不想使用結構Api。 我正在使用下面的代碼上傳圖片在twitter上,它完美的作品,我可以使用此代碼上傳視頻後修改,如果任何人有想法如何我可以做到這一點使用此代碼再見。 謝謝在Twitter上發佈視頻以編程方式
func post(tweetString: String, tweetImage: Data ,withUserID :String) {
let uploadUrl = "https://upload.twitter.com/1.1/media/upload.json"
let updateUrl = "https://api.twitter.com/1.1/statuses/update.json"
let imageString = tweetImage.base64EncodedString(options: NSData.Base64EncodingOptions())
let client = TWTRAPIClient.init(userID: withUserID)
let requestUploadUrl = client.urlRequest(withMethod: "POST", url: uploadUrl, parameters: ["media": imageString], error: nil)
client.sendTwitterRequest(requestUploadUrl) { (urlResponse, data, connectionError) -> Void in
if connectionError == nil {
if let mediaDict = self.nsdataToJSON(data: (data! as NSData) as Data as Data as NSData) as? [String : Any] {
let media_id = mediaDict["media_id_string"] as! String
let message = ["status": tweetString, "media_ids": media_id]
let requestUpdateUrl = client.urlRequest(withMethod: "POST", url: updateUrl, parameters: message, error: nil)
client.sendTwitterRequest(requestUpdateUrl, completion: { (urlResponse, data, connectionError) -> Void in
if connectionError == nil {
if let _ = self.nsdataToJSON(data: (data! as NSData) as Data as Data as NSData) as? [String : Any] {
print("Upload suceess to Twitter")
}
}
})
}
}
}
}
func nsdataToJSON (data: NSData) -> AnyObject? {
do {
return try JSONSerialization.jsonObject(with: data as Data, options: .mutableContainers) as AnyObject
} catch let myJSONError {
print(myJSONError)
}
return nil
}
請不要使用不相關的標籤。你的問題與Objective-C編程語言無關。 – rmaddy
@rmaddy請不要刪除objective-c標籤我只需要ans它不管它在swift或objective-c – ZAFAR007