Callback url not approved despite being provided T

2019-04-01 19:07发布

问题:

In the twitter console I have a callback url from firebase linked. Yet when I try to authenticate using twitter I get the error:

"Request failed: forbidden (403)" UserInfo={NSLocalizedFailureReason=Twitter API error : <?xml version="1.0" encoding="UTF-8"?><errors><error code="415">Callback URL not approved for this client application. Approved callback URLs can be adjusted in your application settings</error></errors> (code (null))

Whats going on? I have tried everything , and no one else on the internet seems to have this issue but me?

回答1:

I face same issue we no need to change in code side, we just need to change some setting in developer account of twitter (tested solution)

You need to add the consumer/api key in Callback URL using below format

Ref link : https://developer.twitter.com/en/docs/basics/callback_url.html

twitterkit-consumer/api key://

You need to add twitterkit-yourConsumerKey in info.plist

<array>
        <dict>
            <key>CFBundleTypeRole</key>
            <string>Editor</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>twitterkit-your Consumer Key (API Key)</string>
            </array>
        </dict>
    </array>


回答2:

So heres what worked for me. I used the regular old twitter Kit ( for swift and objective c ) given on twitters GitHub here:

https://github.com/twitter/twitter-kit-ios/wiki

This solved my call back url problems ( I was originally using Alamofire )

This is a good example of an error free network call :

 let client = TWTRAPIClient()
    let statusesShowEndpoint = "https://api.twitter.com/1.1/users/show.json"

    var clientError : NSError?

    let request = client.urlRequest(withMethod: "GET", urlString: statusesShowEndpoint, parameters: ["user_id": "\(currentProfileTwitterUid)"], error: &clientError)

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

        do {
            if let json = try JSONSerialization.jsonObject(with: data!, options: []) as? Any{

            if let dict = json as? [String : Any]{
                //print(json)


            }
            }



        } catch let jsonError as NSError {
            print("json error: \(jsonError.localizedDescription)")
        }
    }

Hope this helps anyone else!