以编程方式在 Twitter 上发布视频 [英] Post Video On Twitter Programmatically

查看:31
本文介绍了以编程方式在 Twitter 上发布视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我如何使用 Twitterkit 或任何其他编程方法(swift 或 Objective-c)在 Twitter 上发布视频.我看过很多与此相关的帖子,但没有找到任何解决方案.我不想使用织物 Api.我正在使用以下代码在 twitter 上上传图片,它运行良好,我可以使用此代码在修改后上传视频,如果有人知道我如何使用此代码完成此操作.谢谢

Can anyone please tell me how i can post Video on Twitter using Twitterkit or any other method programmatically in (swift or objective-c). I'v seen many posts related to this but did't find any solution. I don't want use fabric Api. I'm using below code for uploading image on twitter and it works perfectly, can i use this code for uploading video after modification on it, if any one have idea how i can done this bye using this code. thanks

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
    }

推荐答案

上传视频与上传图片明显不同.这基本上是一个两步过程.首先,您将视频文件上传到 Twitter.其次,您创建一条引用上传视频的新推文.此外,您必须密切注意 Twitter 对视频的要求规格.

Uploading video differs significantly from uploading an image. It's basically a two-step process. First, you upload the video file to Twitter. Second, you create a new tweet that references the uploaded video. Also, you must pay close attention to the Twitter's requirements for the video's specifications.

这里是使用 Python 语言的示例.它使用 TwitterAPI 包.

Here is an example using the Python language. It uses the TwitterAPI package.

这篇关于以编程方式在 Twitter 上发布视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆