Posting using REST API fails on Swift TwitterKit

Asked 2 years ago, Updated 2 years ago, 152 views

Xcode 7.1, Swift 7.1 and Fabric Twitter 1.13.1.

I use Fabric's TwitterKit to call "POST statuses/update" on Twitter's REST API, but it doesn't succeed.The code is as follows:

let client=TWTRAPICclient()
    varclientError: NSError?
    letendPoint="https://api.twitter.com/1.1/statuses/update.json"

    let params=["status": "testTweet" ]

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

    client.sendTwitterRequest(request){(response,data,connectionError)->Void in
        if(connectionError==nil){
            print("success");
        }
        else{
            print("Error:\(connectionError)")
        }
    }

The following error will appear:

 Optional (Error Domain=TwitterAPIErrorDomain Code=220 
"Request failed: forbidden (403)" 

UserInfo={NSLocalizedFailureReason=Twitter API error:
 Your credentials do not allow access to this resource. (code 220), 
 NSErrorFailingURLKey=https://api.twitter.com/1.1/statuses/update.json,
 NSLocalizedDescription=Request failed: forbidden (403)}

I suspected the permissions of the Twitter application and looked it up, but it says Read&Write and it looks correct.
The GET states/show/:id call was successful.

If anyone knows the cause, could you tell me?

swift twitter twitter-fabric

2022-09-30 21:11

1 Answers

The error message indicates a problem around authentication.

You need four things to access Twitter:(Based on the question, I think it has already been made.)

To set these credentials to TwitterKit, first

https://docs.fabric.io/ios/twitter/twitterkit-setup.html

as described in
Twitter.sharedInstance().startWithConsumerKey("your_key", consumerSecret:"your_secret")
Fabric.with ([Twitter.sharedInstance()])

Register 1 and 2 in the section

Do you write this part on AppDelegate? If it's not written, please write it down.

Further

https://docs.fabric.io/ios/twitter/authentication.html#using-existing-tokens

Register 3 and 4 using the logInWithExistingAuthToken:authTokenSecret:completion: method described in the .

If you write the code to tweet in the completion block of this method, you will be able to tweet.


2022-09-30 21:11

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.