We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
pakk4
2 years agoNew member | Level 2
Error 404 when trying to get refresh token using CURL C++
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* cur...
Здравко
2 years agoLegendary | Level 20
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.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
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!