Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
Hello, I am currently trying to get the refresh token for my scoped app using CURL C++ but I am just getting error 404 from the buffer.
Here is my code:
void get_refresh_token()
{
CURL* curl = curl_easy_init();
if (curl)
{
struct curl_slist* header_list = 0;
header_list = curl_slist_append(header_list, "Authorization: Basic <APP_KEY>:<APP_SECRET>");
header_list = curl_slist_append(header_list, "Content-Type: application/x-www-form-urlencoded");
header_list = curl_slist_append(header_list, "Dropbox-API-Arg: {\"code\":\"/<ACCESS_CODE>\",\"grant_type\": \"authorization_code\"}");
std::string buffer;
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header_list);
curl_easy_setopt(curl, CURLOPT_URL, "https://api.dropboxapi.com/oauth2/token");
CURLcode result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
curl_global_cleanup();
}
Any help would be appreciated, thank you.
Based on this code, it looks like you're not formatting this HTTP request correctly:
Please refer to the /oauth2/token documentation here for information on how to configure this request.
Hi @pakk4,
Before trying to do something read carefully all relevant documents (i.e at least curllib and Dropbox API documentation), something you skipped as seems. 🙋
In addition to what Greg said, be careful not to pass unsupported types (don't rely on C++ type checking since libcurl is NOT C++, but a clear C library, so wont receive error or warning). By default (i.e. not explicitly changed) data type is supposed to be a pointer to FILE, not something else!
Some pseudocode follows:
const char* constexpr oauth2_token = "https://api.dropboxapi.com/oauth2/token";
void somefunc() {
auto callback = [](char *ptr, size_t size, size_t nmemb, void *userdata) -> size_t {
std::string& dataBuf = *(std::string*)userdata;
dataBuf.append(ptr, size*nmemb);
return size*nmemb;
};
CURL *curl = curl_easy_init();
if (curl) {
std::string dataBuf;
std::string body("grant_type=authorization_code&code=");
body += "<your access code>";
curl_easy_setopt(curl, CURLOPT_URL, oauth2_token);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body.c_str());
curl_easy_setopt(curl, CURLOPT_USERPWD, "<APP_KEY>:<APP_SECRET>");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&dataBuf);
CURLcode res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
// ... do whatever you want with your result here.
}
}
Adapt it to your needs.
Good luck.
Hi there!
If you need more help you can view your support options (expected response time for a ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!