TwitterKit sharing stopped working

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) //we have this from logInWithCompletion() in the previousVC

      let imageData = UIImagePNGRepresentation(self.cardView.takeSnapshot())
      let uploadParams = ["media" : imageData!.base64EncodedStringWithOptions(NSDataBase64EncodingOptions.Encoding64CharacterLineLength)]
      //TODO: Handle error properly (do / catch?)
      let uploadRequest = client.URLRequestWithMethod(kTwitterPOSTmethod, URL: kTwitterUploadURL, parameters: uploadParams, error: nil)

      //First we upload the image via a request
      client.sendTwitterRequest(uploadRequest, completion: { (response, uploadResultData, error) -> Void in

.. with the sendTwitterRequest method returning the above error.

? SDK TwitterKit, - " ".

+4
1

2.0 TwitterKit, .

0

Source: https://habr.com/ru/post/1623847/


All Articles