1

I dev on Dropbox API, using C# universal app.

public async Task<string> Httpclient(string link) {
    HttpClient client = new HttpClient();
    HttpResponseMessage response= await client.GetAsync(link);
    return await response.Content.ReadAsStringAsync();
}

public async Task<Model.Get_Current_Account.RootObject> get_current_account(string _accessToken) {
    var query = await mainViewModel.Httpclient("https://api.dropboxapi.com/2/users/get_current_account?access_token="+_accessToken);
    if (query != null) {
        var get_data = JsonConvert.DeserializeObject<Model.Get_Current_Account.RootObject>(query);
        return get_data;
    } else
        return null;
}

var query produces an error:

Error in call to API function "users/get_current_account": Must provide HTTP header "Authorization" or URL parameter "authorization"

Antti29
  • 2,953
  • 12
  • 34
  • 36
onizuka satan
  • 77
  • 1
  • 4

2 Answers2

1

Reading the dropbox API docs suggests you should be passing an authorization header (which matches the error you are receiving)

Authorization: Bearer <access token>

this answer shows how to add headers to HttpClient

Community
  • 1
  • 1
Jay
  • 2,077
  • 5
  • 24
  • 39
  • Thanks but It require a "method" is POST.(Method = "get") – onizuka satan Feb 09 '16 at 08:24
  • This is correct. Another option, per the error message you posted, is to use an "authorization" URL parameter, instead of the "access_token" URL parameter used in your code. – Greg Feb 09 '16 at 18:31
  • Further, the method should be POST, not GET, but that's another issue. – Greg Feb 09 '16 at 18:31
0

Instead of using HttpClient, try using an HttpWebRequest and set the HTTP header that the API is looking for:

public async Task<string> Httpclient(string link, string token)
{
    try
    {
        var request = (HttpWebRequest)WebRequest.Create(link);
        request.Accept = "application/json";
        request.Headers.Add(
            HttpRequestHeader.Authorization, 
            string.concat("Bearer ", token));
        request.Method = "get";
        var response = await request.GetResponseAsync();
        var stream = response.GetResponseStream();
        if (stream != null)
        {
            using (var reader = new StreamReader(stream))
            {
                return reader.ReadToEnd();
            }
        }
        else return string.Empty;
    }
    catch { return string.Empty; }
}

This should get you headed in the right direction.

You will need to provide token data for authorization to be successful.

Lemonseed
  • 1,644
  • 1
  • 15
  • 29