简体   繁体   中英

Error code 403 when using guest authentication with TwitterKit iOS for getting user timeline

I am using Fabric's twitter kit for getting a username's tweets in my iOS application by making a request to the REST API endpoint " https://api.twitter.com/1.1/statuses/user_timeline.json "

I am have correctly set up my "consumer key" and "consumer secret key" as provided by the Fabric app in my AppDelegate and info.plist , but I repeatedly get the following error message -

Error: Optional(Error Domain=TwitterAPIErrorDomain Code=200 "Request failed: forbidden (403)" UserInfo={NSErrorFailingURLKey= https://api.twitter.com/1.1/guest/activate.json , NSLocalizedDescription=Request failed: forbidden (403), NSLocalizedFailureReason=Twitter API error : Forbidden. (code 200)})

My code is as under follows -

        Twitter.sharedInstance().startWithConsumerKey(TWITTER_CONSUMER_KEY, consumerSecret: TWITTER_CONSUMER_KEY_SECRET)
        Fabric.with([Twitter.sharedInstance()])

        let userId = Twitter.sharedInstance().sessionStore.session()?.userID
        let client = TWTRAPIClient.init(userID: userId)
        let params = ["screen_name": twitterUsername, "count" : "10"]
        var clientError : NSError?

        let request = client.URLRequestWithMethod("GET", URL: TWITTER_TIMELINE_ENDPOINT, parameters: params, error: &clientError)

        client.sendTwitterRequest(request) { (response, data, connectionError) -> Void in
            if(connectionError == nil) {
                self.twitterJson = self.nsdataToJSON(data!)!
                self.constructTweetView(self.twitterJson)
            }
            else {
                print("Error: \(connectionError)")
            }

I am on the most recent version of TwitterKit(>2.0)

How can I go about resolving this ?

Thanks!

Add key in exception domains as shown in info.plist. Following fixed bug for me.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM