I\'m writing my own Box SDK for WP8 to make the most out of Tasks. I am having trouble obtaining an access token. I always get this as a return:
{\"error\":\
I think that including the redirect_uri
in your request body could be complicating things, particularly because it looks to be set to an invalid value (https://CloudBoxWP8
) You might resolve this by setting your app to handle a custom protocol (cloudboxwp8://
) and pre-configuring Box to redirect to that when the token is granted.
cloudboxwp8
. cloudboxwp8://tokengranted
. Implement your token handling logic here.redirect_uri
field, set the value to the custom protocol and endpoint from step 2. Save your changes.redirect_uri
from your request body and try your request again.The request/response would be helpful. It looks like you are UrlEncoding the entire query string instead of just each value. Which would be submitted to us as: grant_type%3Dauthorization_code%26code%3Dxyz%26client_id%3Dxyz%26client_secret%3Dxyz%26redirect_uri%3Dxyz
Instead of: grant_type=authorization_code&code=xyz&client_id=xyz&client_secret=xyz&redirect_uri=xyz
in Windows phone 8.1 WinRT
Dictionary<string, string> contentList = new Dictionary<string, string>();
contentList.Add("code", code);
contentList.Add("client_id", client_id);
contentList.Add("client_secret", clientSecret);
contentList.Add("redirect_uri", redirectUri);
contentList.Add("grant_type", "authorization_code");
FormUrlEncodedContent content = new FormUrlEncodedContent(contentList);
var response = await client.PostAsync(baseURL, content);
YouTubeAutenticationResponse res = JsonConvert.DeserializeObject<YouTubeAutenticationResponse>(await response.Content.ReadAsStringAsync());
public class YouTubeAutenticationResponse
{
[JsonProperty("access_token")]
public string AccessToken { get; set; }
[JsonProperty("token_type")]
public string TokenType { get; set; }
[JsonProperty("expires_in")]
public string ExpiresIn { get; set; }
[JsonProperty("refresh_token")]
public string RefreshToken { get; set; }
}
It's not listed anywhere on the Box API documentation, but the request for retrieving the access token requires the header Content-Type: application/x-www-form-urlencoded
I was also stuck on this part for a while until I found the answer on StackOverflow. I forget the link to it though.