【问题标题】:Attempts to access rapidAPI yahoo finance give me error 403 through swift尝试访问 rapidAPI yahoo Finance 通过 swift 给我错误 403
【发布时间】:2020-04-20 16:46:41
【问题描述】:

我正在尝试使用 rapidAPI 来访问个人项目的 Yahoo Finance API。我注册了一个免费帐户并获得了一个 API 密钥。 Rapid API 允许他们的用户复制和粘贴代码来请求数据,所以我使用他们的演示代码来访问 API。在尝试访问有关股票的详细信息时,这是为了快速:

import Foundation

let headers = [
"x-rapidapi-host": "apidojo-yahoo-finance-v1.p.rapidapi.com",
"x-rapidapi-key": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" //private key 
]

let request = NSMutableURLRequest(url: NSURL(string: "https://apidojo-yahoo-finance- 
v1.p.rapidapi.com/stock/get-detail?region=US&lang=en&symbol=APPL")! as URL,
                                    cachePolicy: .useProtocolCachePolicy,
                                timeoutInterval: 10.0)
request.httpMethod = "GET"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
    if (error != nil) {
        print(error)
    } else {
        let httpResponse = response as? HTTPURLResponse
        print(httpResponse)
    }
})

dataTask.resume()

当我运行这段代码时,它给了我错误 403。这意味着根据他们的website,这些数据是被禁止的。我尝试过使用其他 API 并复制和粘贴演示代码,它们工作正常。此 API 不应贬值,因为它在网站演示中运行。这是我在 Xcode 中给出的返回消息:

【问题讨论】:

  • 在这里遇到了类似的问题,请问您发现问题所在了吗?
  • @ishaym 很遗憾,没有。我认为这个 API 可能会被弃用。

标签: swift api yahoo-finance rapidapi


【解决方案1】:

我刚刚检查了Yahoo Finance API。 GET /get-detail 端点现在似乎已被弃用。尽管它已被弃用,但它仍然对我有用。

确保订阅此 API。这可能是 403 代码的原因

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-19
    • 1970-01-01
    • 1970-01-01
    • 2022-12-19
    • 1970-01-01
    相关资源
    最近更新 更多