2012-03-26 14 views
6

Sto provando a configurare una semplice app che utilizza l'API di Yahoo Fantasy Sport e consente l'esecuzione di query tramite YQL.Problema con Yahoo Sports API

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; 
    } 

V'è una certa nascosto qui dentro, ho una classe personalizzata per rendere l'url ok per l'API di Yahoo. Ecco la struttura dell'URL che il metodo OAuth.GetUrl() restituisce

http://query.yahooapis.com/v1/yql?diagnostics=true&format=xml&oauth_consumer_key=mykey&oauth_nonce=rlfmxniesu&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1332785286&oauth_version=1.0&q=select%20%2A%20from%20fantasysports.games%20where%20game_key%20in%20%28%27268%27%29&oauth_signature=NYKIbhjoirJwB6ADxVq5DOgLW1w%3D

Con questo, mi sembra sempre di ottenere Errore di autenticazione. La tabella fantasysports.games richiede un livello di sicurezza maggiore di quello fornito, hai fornito APP ma almeno USER è atteso

Non sono sicuro di cosa significhi, sto passando le mie informazioni di autenticazione all'api, ma sembra che ho bisogno più permessi. Qualcuno ha un esempio funzionante di questo. Se necessario, posso fornire codice al metodo GetUrl, ma è più o meno una copia incolla da qui

http://andy.edinborough.org/Getting-Started-with-Yahoo-and-OAuth

Fatemi sapere se avete domande. Grazie!

+0

hai mai questo numero? –

+0

@RyanDrost Non l'ho fatto –

+0

Se qualcuno ha qualche idea su come estrarre dati di giocatori semplici (che dovrebbero essere disponibili pubblicamente?) Per favore aiutatemi. Qualcuno ha capito come far funzionare un comando YQL nella sua app Web MVC? – dave317

risposta

0

non ho potuto farlo funzionare con il YQL, ma sono stato in grado di ottenere il risultato giocatori dati e progetti, ecc, utilizzando direttamente le API a https://fantasysports.yahooapis.com/fantasy/v2/

esempio per ottenere il giocatore NFL David Johnson dettagli:

GET /fantasy/v2/players;player_keys=371.p.28474 HTTP/1.1

Host: fantasysports.yahooapis.com

Autorizzazione: Bearer [[ Base64 ClientId codificato: Segreto]]

Content-Type: application/json

Problemi correlati