c++ - 从 Dropbox 在 C++ 中通过 curl 下载文件

标签 c++ curl dropbox

我想在 C++ 程序中使用 curl 从保管箱共享链接下载文件

我找到了一个 dropbox api pdf,它告诉我如何去做

#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:");
     headers = curl_slist_append(headers, "Dropbox-API-Arg: 
     {\"path\":\"/test.txt\"}");
     curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
    curl_easy_setopt(curl, CURLOPT_URL,
    "https://content.dropboxapi.com/2/files/download");
     curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "");
     /* 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;
         }

但是,所提供的评论并没有为我提供太多解释,我无法让它发挥作用。

这三行代码我看不懂:

headers = curl_slist_append(headers, "Authorization: Bearer <ACCESS_TOKEN>");

headers = curl_slist_append(headers, "Content-Type:");

headers = curl_slist_append(headers, "Dropbox-API-Arg:{\"path\":\"/test.txt\"}");

我想我必须更换一些东西,但我不知道是什么

最佳答案

“我想我必须更换一些东西,但我不知道是什么”:更换 <ACCESS_TOKEN>使用您的实际访问 token 。

您还应该将“Content-Type:” header 设置为适合您正在获取的数据的值。

您还必须更改“Dropbox-API-Arg” header 的值以匹配您尝试获取的文件。

关于c++ - 从 Dropbox 在 C++ 中通过 curl 下载文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55773591/

相关文章:

c++ - 什么时候需要初始化指向 nullptr 的指针?

c# - 如何在另一个进程中从 C# 调用 C++ 导出的函数?

PHP curl : how to set body to binary data?

python - 如何获取 pandas xlsxwriter 对象的二进制内容以进行 Dropbox 上传

c++ - 使用 files_put 上传 DropBox 返回身份验证失败

实现纯虚类的 C++ 实例集合

c++ - 使用给定的参数包消除重载函数的歧义

java - Curl 对象到 URL 生成

php - League\OAuth2\Client\Provider\GenericProvider SSL 错误

Nginx 和 Dropbox 文件夹内的符号链接(symbolic link)根目录导致 "File not found."