Dropbox API Ottenere informazioni sull'account per l'utente collegato tramite curl in C ++


Esempio

#include <stdio.h>
#include <curl/curl.h>


int main (int argc, char *argv[])
{
      CURL *curl;
      CURLcode res;

      /* In windows, this will init the winsock stuff */ 
      curl_global_init(CURL_GLOBAL_ALL);
     
      /* get a curl handle */ 
      curl = curl_easy_init();
      if(curl) {

            printf ("Running curl test.\n");

            struct curl_slist *headers=NULL; /* init to NULL is important */
            headers = curl_slist_append(headers, "Authorization: Bearer <ACCESS_TOKEN>");
            headers = curl_slist_append(headers, "Content-Type: application/json");
            curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
             
            curl_easy_setopt(curl, CURLOPT_URL, "https://api.dropbox.com/2/users/get_current_account");
            curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "null");

            /* Perform the request, res will get the return code */ 
            res = curl_easy_perform(curl);

            /* Check for errors */ 
            if(res != CURLE_OK)
                  fprintf(stderr, "curl_easy_perform() failed: %s\n",
                    curl_easy_strerror(res));

            /* always cleanup */
              curl_easy_cleanup(curl);

              printf ("\nFinished curl test.\n");

      }
      curl_global_cleanup();

      printf ("Done!\n");
      return 0;

}

<ACCESS_TOKEN> deve essere sostituito con il token di accesso.