2

I'm just starting out with APIs, and full disclosure... I copy and pasted from this answer: How do I make calls to a REST api using c#? But clearly I'm pretty much lost.

I'm trying to start simple by just getting info from the dropbox api.

I plugged in the api URL but I cannot figure out how to pass in the authentication token or the account ID.

private const string URL = "https://api.dropboxapi.com/2-beta-2/users/get_current_account";
        private const string urlParameters = "access_token=xxxxxxxxxxxxx";

        static void Main(string[] args)
        {
            HttpClient client = new HttpClient();
            client.BaseAddress = new Uri(URL);

            // Add an Accept header for JSON format.
            client.DefaultRequestHeaders.Accept.Add(
            new MediaTypeWithQualityHeaderValue("application/json"));

            // List data response.
            HttpResponseMessage response = client.GetAsync(urlParameters).Result;  // Blocking call!
            if (response.IsSuccessStatusCode)
            {
                // Parse the response body. Blocking!
                var dataObjects = response.Content.ReadAsAsync<IEnumerable<DataObject>>().Result;
                foreach (var d in dataObjects)
                {
                    Console.WriteLine("{0}", d.Name);
                    Console.ReadKey();
                }
            }

from Dropbox the http request should be:

POST /2-beta-2/users/get_account
Host: https://api.dropboxapi.com
User-Agent: api-explorer-client
Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx
Content-Type: application/json

{
    "account_id": "dbid:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
1

1 Answer 1

0

You probably need to add the Bearer token to the Headers in the request

client.DefaultRequestHeaders.Add("Authorization", "Bearer " + accessToken);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.