javascript - jQuery 中的 Yahoo New Weather API oAuth 调用

标签 javascript jquery oauth

自 1 月 3 日起,雅虎天气有了一个需要 oAuth 的新天气 API https://developer.yahoo.com/weather/

现在我已经从 yahoo 获得了我的客户端 ID(消费者 key )和我的客户端 key (消费者 key )。我的问题是如何在 jquery 或 javascript 中使用 oAuth 调用此 API?

这是调用的样子:

GET /forecastrss?location=sunnyvale,ca HTTP/1.1
Host: weather-ydn-yql.media.yahoo.com
Yahoo-App-Id: YOUR_APP_ID
Authorization: OAuth
oauth_consumer_key="YOUR_CONSUMER_KEY",oauth_signature_method="HMAC-SHA1",oauth_timestamp="YOUR_TIMESTAMP",oauth_nonce="YOUR_NONCE",oauth_version="1.0",oauth_signature="YOUR_GENERATED_SIGNATURE"
cache-control: no-cache

它声明“还请在 header 中包含您的 OAuth 应用程序 ID。”

这在 jquery 中会是什么样子?

我尝试了以下方法:

$.get("https://weather-ydn-yql.media.yahoo.com/forecastrss", { location: "sunnyvale,ca", format: "json", oauth_consumer_key: "Client ID (Consumer Key)", oauth_signature_method: "HMAC-SHA1" } ).done(function( data ) {
        console.log("Data Loaded: " + data);
    });

我得到这个错误:

ERR_ABORTED 401 (Unauthorized)

最佳答案

虽然我没有专门运行这段代码,但它应该像 jQuery 中的其他所有 get 请求一样工作

$.get( url, { location: "sunnyvale,ca", format: "json", oauth_consumer_key: oauth_consumer_key, oauth_signature_method: oauth_signature_method, ... } )
  .done(function( data ) {
    alert( "Data Loaded: " + data );
  });

引用文献 1:jQuery API https://api.jquery.com/jQuery.get/

Ref2:雅虎 API:https://developer.yahoo.com/weather/documentation.html

关于javascript - jQuery 中的 Yahoo New Weather API oAuth 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54112880/

相关文章:

authentication - oAuth 2.0 - 代表用户行事

ruby-on-rails - 如何在 facebook graph api 中处理过期的访问 token

javascript - 如何对特定位置使用 GET ELEMENT

javascript - ReactJS - 将对象传递给操作时出错

php - 新手 ajax (jquery) 问题

javascript - 如何在隐藏输入中的逗号分隔列表中添加/删除单击时的属性值

jquery - TS-2304 错误 - 在 'Iterable' 文件中导入 "jquery"时在 TypeScript 中找不到名称 ".ts"

javascript - 在 $(document) 上绑定(bind)事件时绑定(bind)上下文

javascript - 添加滑动功能以增加项目

node.js - crypto.getCurves 未定义