简体   繁体   English

验证后Yahoo API的问题

[英]Problems with Yahoo API after authentication

I've been searching for answers for this for a while but I can't seem to find the answer. 我一直在寻找答案,但是似乎找不到答案。 I've tried several things, all of which I'll list here, and hopefully someone can point me in the right direction. 我已经尝试了好几件事,所有这些我都会在这里列出,希望有人可以指出正确的方向。

First off, I've built a simple Node app using the Hapi framework. 首先,我使用Hapi框架构建了一个简单的Node应用程序。 In addition, I'm using the Bell library, also from the Hapi guys, to authenticate with Yahoo and hapi-auth-cookie to set my session with the authentication results. 另外,我正在使用同样来自Hapi的Bell库对Yahoo和hapi-auth-cookie进行身份验证,以使用身份验证结果设置会话。 This, from what I can tell, is working perfectly. 据我所知,这是完美的。

Bell, once the user is authenticated, provides me with a token and a secret. 用户通过身份验证后,Bell向我提供了令牌和机密。

The token looks something like this: 令牌看起来像这样:

A=vvnxl1_FhCK6FPEFbIA.p_N8cSet7Ifmye.i3mWa6hrlh7fXecZhQvumjKSXPkRGfcj2BaFSmZCWPXeW67G8kqiS4G3Z7yBR

The secret looks something like this: 这个秘密看起来像这样:

9e17917hsjf863c220c35f3f3385b6e4cd586c84

So once I authenticate and am redirected to my homepage, i have these two and a cookie is set. 因此,一旦我通过身份验证并重定向到我的主页,便拥有了这两个并设置了一个cookie。 It's my understanding that I'm ready roll. 据我了解,我已经准备好了。 I then try to hit the Yahoo API using the following URL: 然后,我尝试使用以下URL来访问Yahoo API:

https://fantasysports.yahooapis.com/fantasy/v2/leagues;league_keys=328.l.5668/standings?format=json

The response to hitting this URL is: 点击此网址的响应是:

{
"error":
    {
        "lang": "en-US",
        "description": "Please provide valid credentials. OAuth oauth_problem=\"unable_to_determine_oauth_type\", realm=\"yahooapis.com\""
     }
 }

Obviously the URL I'm trying to hit is incomplete. 显然,我要访问的URL不完整。 However, I am unsure of what the required params are. 但是,我不确定所需的参数是什么。 I've been to the Yahoo docs 1000 times, but I can't seem to find this specific answer. 我去过Yahoo docs 1000次了,但是我似乎找不到这个具体答案。 All the examples there mostly relate to the authentication bit, which I should be done with. 那里的所有示例大多与身份验证位有关,我应该这样做。 So, hoping I'd get lucky, I started trying to pass in the token and secret in the URL. 因此,希望我能走运,我开始尝试在URL中传递令牌和秘密。 In this one I tried API URL + token + secret + signature. 在这一部分中,我尝试了API URL +令牌+机密+签名。 The token and secret I'm using are the ones provided by Bell referenced above: 我正在使用的令牌和秘密是上面引用的Bell提供的:

https://fantasysports.yahooapis.com/fantasy/v2/leagues;league_keys=328.l.5668/standings?format=json&&oauth_token=A=tqq2L3D54ATsQZbgHB95b0ZyCj_kgq01R69vTulZ6lP9evhzddrIaksmd6u21fNSPFQ8WtVBsWr9GFk1zQtsw_OP4pKKaDKs2TxHlqwAYp4ZyIkthzPcSnJQka.J2THeK8BHC8eeisT4EeQpMqcDgefX6Hbb1CsQ_bD00ECd3AE.uGdF_6sm&oauth_secret=b5d2359f191cc72cfd318b5cf&oauth_signature=524a4f6e1407acd00a98f53973180%26b5d2359f191cc4c7d7d7bfd318b5cf

Now, it tells me that the token was rejected: 现在,它告诉我令牌已被拒绝:

{
    "error": {
        "lang": "en-US",
        "description": "Please provide valid credentials. OAuth oauth_problem=\"token_rejected\", realm=\"yahooapis.com\""
    }
}

I also tried it without the signature first, in which case the error tells me that the signature is missing. 我还尝试了没有签名的情况,在这种情况下,错误告诉我缺少签名。

Any help here would be appreciated. 在这里的任何帮助,将不胜感激。 From searching for the past week I see that the Yahoo API isn't the easiest thing to work with, but hopefully someone has some insight here as it seems that I'm so close. 通过搜索过去一周,我发现Yahoo API并不是最容易使用的东西,但是希望有人在这里有所了解,因为我似乎很亲近。 I hope I included all the info you need, thank you!! 我希望我包括了您需要的所有信息,谢谢!!

Once user is authenticated properly then you will have the "oauth_token" and the "oauth_token_secret", which you have as you mentioned. 正确验证用户身份后,您将拥有提到的“ oauth_token”和“ oauth_token_secret”。

Now, while trying to access the Yahoo API, you need to provide the "token" and "secret" as per oauth spec, so that Yahoo understands that you are allowed to access their APIs. 现在,在尝试访问Yahoo API时,您需要按照oauth规范提供“令牌”和“秘密”,以便Yahoo理解您被允许访问其API。

This is how oauth works, you can either provide the oauth information as part of "Authorization" header or query params with the url. oauth的工作方式就是这样,您可以将oauth信息作为“授权”标头的一部分提供,也可以使用url查询参数。

"oauth_token_secret" (with all other call information) should be used to generate the "oauth_signature" which yahoo will verify at their end. “ oauth_token_secret”(以及所有其他呼叫信息)应用于生成“ oauth_signature”,雅虎将在其末尾进行验证。 "secret" is not supposed to be sent as it is, while accessing their apis. 访问他们的api时,不应原样发送“秘密”。

Note that, oauth information doesn't only involve the "token" and the "signature" but also the "nonce", "timestamp", "version", "signature_method", etc. All the information (along with secret) will be used to generate the signature which will then be passed to the yahoo as part of their api call. 请注意,oauth信息不仅涉及“令牌”和“签名”,而且还涉及“ nonce”,“ timestamp”,“ version”,“ signature_method”等。所有信息(以及机密信息)都将是用于生成签名,然后将其作为api调用的一部分传递给yahoo。

Oauth docs can be found at http://tools.ietf.org/pdf/rfc5849.pdf Oauth文档可在http://tools.ietf.org/pdf/rfc5849.pdf中找到

HTH HTH

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM