Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3630

Microsoft Live custom C# REST API error 415

$
0
0

I'm trying to get data from the Microsoft Live API. However, when I try to get the access_token, I instead get a 415 (Unsupported Media Type) error message. I have looked pretty much everywhere, but I can't find any answer (that worked for me).

Here is my (partial) code that tries to get the token (dataToWrite is cut-up for readability, it's one line in the actual code):

WebRequest request;request = WebRequest.Create("https://login.live.com/oauth20_token.srf");request.Method = "POST";request.ContentType = "application/x-www-form-urlencoded";var dataToWrite = "code=[code]&  client_id=[client_id]&  client_secret=[client_secret]&  redirect_uri=[redirect_uri]&  grant_type=authorization_code";var buffer = Encoding.ASCII.GetBytes(dataToWrite);request.ContentLength = buffer.Length;var dataStream = request.GetRequestStream();dataStream.Write(buffer, 0, buffer.Length);dataStream.Close();var response = request.GetResponse();var responseStream = response.GetResponseStream();

Where the '[]' are:

  • [code] is a string, given by Microsoft after user logs in (this part of the code works);
  • [client_id] is a string, given by Microsoft, representing my client id;
  • [client_secret] is a string, given by Microsoft, representing my client secret;
  • [redirect_uri] is the URL of the site's return location (same as the URL used in the code for the user consent(see [code]))

According to the manual of Microsoft Live API(http://msdn.microsoft.com/en-us/library/live/hh243647.aspx) this should work. However, the documentation isn't very detailed.

Does anyone know why I keep getting the error?


Viewing all articles
Browse latest Browse all 3630

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>