TwitterKit 401 error

swift
twitterkit

#1

Hi, I’m using the code below to send a simple tweet, but I keep getting the following error:

Error Domain=TWTRNetworkingErrorDomain Code=-1011 “Request failed: unauthorized (401)” UserInfo={NSLocalizedFailureReason=, TWTRNetworkingStatusCode=401, NSErrorFailingURLKey=https://api.twitter.com/1.1/statuses/update.json, NSLocalizedDescription=Request failed: unauthorized (401)}

I am using xCode 8 and Swift 3. I believe my application is setup correctly in Application Management in the dashboard. Any help would be GREATLY appreciated. I’ve been scouring the net for answer but have not been able to figure out what I’m doing wrong. Thanks!

if (Twitter.sharedInstance().sessionStore.session() != nil)
        {
            let store = Twitter.sharedInstance().sessionStore
            if let userid = store.session()?.userID {
                let client = TWTRAPIClient(userID: userid)
                let tweetText = helpMessage + " " + (googleLink?.description)!

                client.sendTweet(withText: tweetText, completion: { (tweet, error) in
                    print(error!)
                })
            }
        }


#2

@Baldman68

I and someone are also facing 401 error if text contains some specific characters( “^ < > \ | `”)

Does it match for your case?

the thread is here:


#3

@buncho

I don’t believe that’s my case. Ultimately I’m trying to share a message (no special characters) and a link to Google Maps, but I’m testing without adding the link and still getting the error.

Thanks for your reply though!


#4

Is this using Twitter Kit 3? Are you using TWTRComposer? Please share more detail of how you are calling the API and the details of any errors. Thank you.


#5

Sorry, I thought I included all the relevant info? The code I’m using and the actual error I’m getting is in my original post. I’m not sure what else to show you? You can see I’m not using the composer. My app design does not lend itself to using the composer.

I’d be happy to provide any more info if you can tell me what you need.


#6

And I just installed TwiiterKit using CocoaPods so yes I believe I’m using version 3


#7

So given that info, is there any help anyone can give? I’m really stuck and the error message is not very helpful, so I don’t even know where to look for my problem?


#8

So the issue was using CocoaPods I was not setting the version specifically. I was using “pod ‘TwitterKit’” I changed the line in the podfile to “pod ‘TwitterKit’, ‘~> 3.0’” and everything seems to be working correctly now.


#9

Unfortunately here the same problem, working on iOS 11 beta with TwitterKit 3.0.4. Followed instructions in https://dev.twitter.com/twitterkit/ios/migrate-social-framework but keep getting this error : CredStore - performQuery - Error copying matching creds. Error=-25300, query={
class = inet;
“m_Limit” = “m_LimitAll”;
ptcl = htps;
“r_Attributes” = 1;
sdmn = “https://api.twitter.com”;
srvr = “api.twitter.com”;
sync = syna;
}
and after that :
Did encounter error sending Tweet: Error Domain=TWTRNetworkingErrorDomain Code=-1011 “Request failed: unauthorized (401)” UserInfo={NSLocalizedFailureReason=, TWTRNetworkingStatusCode=401, NSErrorFailingURLKey=https://api.twitter.com/1.1/statuses/update.json, NSLocalizedDescription=Request failed: unauthorized (401)}

Could anyone please advice ?
Thanks, Frank