0

I have the access token. How can I make a request using the token in c#? Here is what I have tried unsuccessfully resulting in error 400 Bad Request.

Note: the url was copied from the YQL console

public static void Request(string token)
        {
            var request =
                WebRequest.Create(
                    @"https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20fantasysports.leagues%20where%20league_key%3D'371.l.4019'&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys");

            request.Headers["Authorization"] = $"Bearer {token}";
            request.Method = "GET";
            request.ContentType = "application/xml;charset=UTF-8";
            using (var response = request.GetResponse())
            {
                using (var stream = response.GetResponseStream())
                {
                    if (stream == null) return;
                    var reader = new StreamReader(stream, Encoding.UTF8);
                    var responseString = reader.ReadToEnd();
                }
            }
        }
AlG
  • 14,697
  • 4
  • 41
  • 54
declouet
  • 307
  • 3
  • 10
  • You sure you don't need the full OAuth header? See https://developer.yahoo.com/boss/search/boss_api_guide/codeexamples.html (C# example toward the middle bottom) – AlG Sep 13 '17 at 14:09
  • I successfully followed the Explicit Grant Flow to get the access token as described in the Yahoo Oauth 2.0 Guide. After acquiring the access token I am trying to make an API request as described here [developer.yahoo.com/oauth2/guide/apirequests/](https://developer.yahoo.com/oauth2/guide/apirequests/) to no avail. – declouet Sep 14 '17 at 15:11
  • Excellent. Check out https://stackoverflow.com/questions/14488991/adding-authorization-header-to-web-reference – AlG Sep 14 '17 at 16:51
  • Possible duplicate of [Adding Authorization Header to Web Reference](https://stackoverflow.com/questions/14488991/adding-authorization-header-to-web-reference) – AlG Sep 14 '17 at 16:51

0 Answers0