卷曲呼叫Yahoo Weather New api OAuth

时间:2019-01-11 16:49:48

标签: api curl yahoo-api

我正在尝试对新的Yahoo Weather API进行curl调用

https://developer.yahoo.com/weather/

https://developer.yahoo.com/weather/documentation.html

我获得了我的API密钥,并且我的应用已被批准或列入白名单。

但是,我似乎无法通过curl调用来使用OAuth身份验证。我首先尝试与Postman进行呼叫,但已获得授权,但结果为空。根据支持,“在邮递员中使用oauth1可能会出现间歇性错误。”

所以我是否想像这样进行curl调用:

curl --request GET --url 'https://weather-ydn-yql.media.yahoo.com/forecastrss?location=sunnyvale,ca' --header 'Authorization: OAuth oauth_consumer_key="(MY CLIENT ID)",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1547215497",oauth_nonce="kIDevCJSTBi",oauth_version="1.0",oauth_signature="(MY GENERATED OAUTH SIGNATURE)"' --header 'Yahoo-App-Id: "(MY APP ID)"'

但是我得到了返回:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><yahoo:error xmlns:yahoo="http://www.yahooapis.com/v1/base.rng" xml:lang="en-US" yahoo:uri="http://yahoo.com"><yahoo:description>Please provide valid credentials. OAuth oauth_problem=&quot;OST_OAUTH_SIGNATURE_INVALID_ERROR&quot;, realm=&quot;yahooapis.com&quot;</yahoo:description><yahoo:detail>Please provide valid credentials. OAuth oauth_problem=&quot;OST_OAUTH_SIGNATURE_INVALID_ERROR&quot;, realm=&quot;yahooapis.com&quot;</yahoo:detail></yahoo:error>

这来自Yahoo Weather Developer页面:

  

GET / forecastrss?location = sunnyvale,ca HTTP / 1.1主机:   weather-ydn-yql.media.yahoo.com Yahoo-App-Id:YOUR_APP_ID   授权: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”缓存控制:无缓存

我做错了什么?真令人沮丧。

1 个答案:

答案 0 :(得分:1)

以下是curl请求的示例:

curl 'https://weather-ydn-yql.media.yahoo.com/forecastrss?location=sunnyvale,ca&format=json&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'

documentation中所述。

YOUR_CONSUMER_KEY:您的消费者密钥
YOUR_TIMESTAMP:Unix时间戳
YOUR_NONCE:nounce
YOUR_GENERATED_SIGNATURE:加密的签名。

以下是使用Postman(如您在描述中使用它)向Yahoo Weather API生成GET请求的步骤。

1)Postman配置: Postman configuration

2)生成curl命令
然后,为了发出卷曲请求,您可以按代码按钮并查看生成的命令。 Generated curl command

在Java,PHP和NodeJS on this page中有一些代码示例。