尽管已提供 Twitter Api,但回调 url 未获批准

Callback url not approved despite being provided Twitter Api

在 Twitter 控制台中,我有一个来自 firebase 链接的回调 url。然而,当我尝试使用 Twitter 进行身份验证时,出现错误:

"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))

这是怎么回事?我已经尝试了所有方法,除了我,网上似乎没有其他人遇到过这个问题?

这就是对我有用的方法。我使用了推特 GitHub 上提供的常规旧推特工具包(用于 swift 和 objective c):

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

这解决了我的回拨 url 问题(我最初使用的是 Alamofire)

这是无错误网络调用的一个很好的例子:

 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)")
        }
    }

希望这对其他人有帮助!

我遇到了同样的问题,我们不需要在代码方面进行更改,我们只需要更改 Twitter 开发者帐户中的一些设置(测试解决方案)

您需要使用以下格式在 回调 URL 中添加 consumer/api 键

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

twitterkit-consumer/api 键://

您需要在info.plist

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