Cannot upload video from Device

ios
api

#1

Hi,

I am trying to share video with Twitter API (WITHOUT Composer). Something strange happens. When I am testing it from Simulator. It’s working, but from Device it’s getting OK, but nothing going to my line.

I am using this function to Upload:

func shareTwitterVideo(data: NSData, text: String) {
        
        let uploadUrl = "https://upload.twitter.com/1.1/media/upload.json"
        let updateUrl = "https://api.twitter.com/1.1/statuses/update.json"

        print("VIDEO DATA ==> \(data.length)")
        
        let videoString = data.base64EncodedStringWithOptions(NSDataBase64EncodingOptions.Encoding64CharacterLineLength)
        let videoDataLength = NSNumber(integer: (data.length)).stringValue
        
        var client = Twitter.sharedInstance().APIClient
        
        var initError: NSError?
        var message : NSMutableDictionary!
        
        message = ["status": self.imageDescription.text, "command" : "INIT", "media_type" : "video/m4v", "total_bytes" : videoDataLength]
        let preparedRequest: NSURLRequest = client.URLRequestWithMethod("POST", URL: uploadUrl, parameters: message as [NSObject : AnyObject], error: &initError)
        var  json : NSDictionary!

        client.sendTwitterRequest(preparedRequest, completion: { (response, data, connectionError) -> Void in
            
            do {
                json = try NSJSONSerialization.JSONObjectWithData(data!, options: .MutableContainers) as! NSDictionary
            } catch  {
                print(connectionError)
            }
            
                //print(json)
                
                let mediaID = json.objectForKey("media_id_string") as! String
                
                client = Twitter.sharedInstance().APIClient
                var uploadError: NSError?
                
                message = ["command" : "APPEND", "media_id" : mediaID, "segment_index" : "0", "media" : videoString]
                let preparedRequest = client.URLRequestWithMethod("POST", URL: uploadUrl, parameters: message as [NSObject : AnyObject], error: &uploadError)
                client.sendTwitterRequest(preparedRequest, completion: { (urlResponse: NSURLResponse?, responseData: NSData?, error: NSError?) -> Void in
                    if error == nil {
                        //client = Twitter.sharedInstance().APIClient
                        var finalizeError: NSError?
                        message = ["command":"FINALIZE", "media_id": mediaID]
                        let preparedRequest = client.URLRequestWithMethod("POST", URL: uploadUrl, parameters: message as [NSObject : AnyObject], error: &finalizeError)
                        client.sendTwitterRequest(preparedRequest, completion: { (urlResponse: NSURLResponse?, responseData: NSData?, error: NSError?) -> Void in
                            if error == nil {
                                client = Twitter.sharedInstance().APIClient
                                var sendError: NSError?
                                let message = ["status": text, "wrap_links": "true", "media_ids": mediaID]
                                _ = NSMutableDictionary(dictionary: message)
                                let preparedRequest = client.URLRequestWithMethod("POST", URL: updateUrl, parameters: message , error: &sendError)
                                client.sendTwitterRequest(preparedRequest, completion: { (urlResponse: NSURLResponse?, responseData: NSData?, error: NSError?) -> Void in
                                    
                                })
                            } else {
                                print("Command FINALIZE failed \n \(error!)")
                            }
                        })
                    } else {
                        print("Command APPEND failed")
                    }
                    
                    print("UPLOAD COMPLETE")
                })
            //} else {
            //    print("Command INIT failed")
            //}
        })
    }

#2

Hey @anton__dev,

If you hit the API directly without using TwitterKit and observe the results via Charles Proxy, what happens?

Note: You can’t use Charles Proxy with TwitterKit as we use SSL Certificate pinning.


#3

Hi @bonnell. Thanks for reply. I have found the issue. My video was 60 FPS. It would be better if you will support 60fps video as well. Because I can’t tell to my users to use only 30 fps for post twitter only. Facebook accepts 60fps.


#4

Thanks for the update! I’ll share this request with the team and update this post with any news on 60 fps.

-Mike


#5