【问题标题】:Callback url not approved despite being provided Twitter Api尽管提供了 Twitter Api,但回调 url 未获批准
【发布时间】:2018-11-07 07:45:48
【问题描述】:

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

怎么了?我已经尝试了所有方法,除了我,互联网上似乎没有其他人有这个问题?

【问题讨论】:

标签: swift firebase twitter twitter-oauth


【解决方案1】:

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

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

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

twitterkit-消费者/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>

【讨论】:

  • 在 Twitter 的政策更新后遇到了类似的问题。应该被接受为正确答案。
  • @Zack。如果答案解决了您的问题,请您接受答案。谢谢
【解决方案2】:

这就是对我有用的方法。我在这里使用了 twitters GitHub 上提供的常规旧 twitter Kit(用于 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)")
        }
    }

希望这对其他人有帮助!

【讨论】:

    猜你喜欢
    • 2018-12-08
    • 2018-02-08
    • 1970-01-01
    • 2014-04-27
    • 1970-01-01
    • 2021-12-30
    • 1970-01-01
    • 2020-08-07
    • 1970-01-01
    相关资源
    最近更新 更多