Reputation: 3772
I'm trying to upload a video via the iOS TwitterKit (latest version). Uploading an image works fine, initializing the video upload as well (receiving a media_id), but I'm getting an Auth error Error Domain=TwitterAPIErrorDomain Code=32 "Request failed: unauthorized (401)"
when trying to upload my first chunk.
Here's part of my code:
let contentType = "multipart/form-data;boundary="+multipartBoundary
let request = Twitter.sharedInstance().APIClient.URLRequestWithMethod("POST", URL: "https://upload.twitter.com/1.1/media/upload.json", parameters: params, error: nil) as! NSMutableURLRequest
request.setValue(contentType, forHTTPHeaderField: "Content-Type")
request.HTTPBody = Network.sharedInstance.bodyDataWithVideoData(videoData!)
Twitter.sharedInstance().APIClient.sendTwitterRequest(request, completion: { (_, data, error) -> Void in
if error != nil || data == nil {
println("error attaching twitter video upload: \(error)")
} else {
println("successfully uploaded video chunk")
println(data)
}
})
What am I missing? Thanks for your help!
Upvotes: 1
Views: 1541
Reputation: 3772
Just found a solution to my question here: https://stackoverflow.com/a/31259870/793146
Turns out that attaching "media" with the base64 string of the video fixes the issue (as opposed to attaching a multipart body).
Upvotes: 1