Uploading photos from my application to a user Twitter account worked fine, and suddenly I get this error:
Domain error = TwitterAPIErrorDomain Code = 32 "Request error: unauthorized (401)" UserInfo = {NSErrorFailingURLKey = https://upload.twitter.com/1.1/media/upload.json , NSLocalizedDescription = Request failed: unauthorized (401), NSLocalizedFailureReason = Twitter API Error: Failed to authenticate you. (code 32)}
Here's how I start a Twitter session:
Twitter.sharedInstance().logInWithCompletion({ (session, error) -> Void in
})
And here, as I upload the media to Twitter, with the error returned by the sendtwitterRequest method:
let store = Twitter.sharedInstance().sessionStore
if let userid = store.session()?.userID {
let client = TWTRAPIClient(userID: userid)
let imageData = UIImagePNGRepresentation(self.cardView.takeSnapshot())
let uploadParams = ["media" : imageData!.base64EncodedStringWithOptions(NSDataBase64EncodingOptions.Encoding64CharacterLineLength)]
let uploadRequest = client.URLRequestWithMethod(kTwitterPOSTmethod, URL: kTwitterUploadURL, parameters: uploadParams, error: nil)
client.sendTwitterRequest(uploadRequest, completion: { (response, uploadResultData, error) -> Void in
.. with the sendTwitterRequest method returning the above error.
? SDK TwitterKit, - " ".