雅虎体育 API 的问题 [英] Issue with Yahoo Sports API
问题描述
我正在尝试设置一个简单的应用程序,该应用程序使用 Yahoo Fantasy sports API,并允许通过 YQL 执行查询.
I am trying to setup a simple app that consumes the Yahoo Fantasy sports API, and allows queries to be executed through YQL.
class Program
{
static void Main(string[] args)
{
string yql = "select * from fantasysports.games where game_key in ('268')";
//var xml = QueryYahoo(yql);
// Console.Write(xml.InnerText);
string consumerKey = "--my key--";
string consumerSecret = "--my secret--";
var xml = QueryYahoo(yql, consumerKey, consumerSecret);
Console.Write(xml.InnerText);
}
private static XmlDocument QueryYahoo(string yql)
{
string url = "http://query.yahooapis.com/v1/public/yql?format=xml&diagnostics=false&q=" + Uri.EscapeUriString(yql);
var req = System.Net.HttpWebRequest.Create(url);
var xml = new XmlDocument();
using (var res = req.GetResponse().GetResponseStream())
{
xml.Load(res);
}
return xml;
}
private static XmlDocument QueryYahoo(string yql, string consumerKey, string consumerSecret)
{
string url = "http://query.yahooapis.com/v1/yql?format=xml&diagnostics=true&q=" + Uri.EscapeUriString(yql);
url = OAuth.GetUrl(url, consumerKey, consumerSecret);
var req = System.Net.HttpWebRequest.Create(url);
var xml = new XmlDocument();
using (var res = req.GetResponse().GetResponseStream())
{
xml.Load(res);
}
return xml;
}
这里隐藏了一些东西,我有一个自定义类来使 Yahoo API 的 url 正常.这是 OAuth.GetUrl() 方法返回的 URL 的结构
There is some hidden in here, I have a custom class to make the url ok for the Yahoo API. Here is the structure of the URL that the OAuth.GetUrl() method returns
有了这个,我似乎总是得到授权错误.表 Fantasysports.games 需要比提供的更高的安全级别,您提供了 APP 但至少需要 USER
With this, I always seem to get Authentication Error. The table fantasysports.games requires a higher security level than is provided, you provided APP but at least USER is expected
我不确定这意味着什么,我正在将我的身份验证信息传递给 api,但似乎我需要更多权限.有没有人有这方面的工作示例.如果需要,我可以为 GetUrl 方法提供代码,但它或多或少是从这里复制粘贴
I am not sure what this means, I am passing my auth information to the api, but it seems I need more permissions. Has anyone have a working example of this. If needed, I can supply code to the GetUrl method, but it is more or less a copy paste from here
http://andy.edinborough.org/Getting-Started-with-Yahoo-and-OAuth
如果您有任何问题,请告诉我.谢谢!
Let me know if you have any questions. Thanks!
推荐答案
我无法使用 YQL 使其工作,但是我能够通过直接使用 https://fantasysports.yahooapis.com/fantasy/v2/
I couldn't make it work using the YQL, but I was able to get the players data and draft result etc, by directly using the APIs at https://fantasysports.yahooapis.com/fantasy/v2/
例如获取 NFL 球员 David Johnson 的详细信息:
e.g. to get NFL player David Johnson details:
GET/fantasy/v2/players;player_keys=371.p.28474 HTTP/1.1
GET /fantasy/v2/players;player_keys=371.p.28474 HTTP/1.1
主持人:fantasysports.yahooapis.com
Host: fantasysports.yahooapis.com
授权:承载 [[Base64 编码的 ClientId:Secret]]
Authorization: Bearer [[Base64 encoded ClientId:Secret]]
内容类型:应用程序/json
Content-Type: application/json
这篇关于雅虎体育 API 的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!