<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Error 404 when trying to get refresh token using CURL C++ in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Error-404-when-trying-to-get-refresh-token-using-CURL-C/m-p/745571#M32798</link>
    <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;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 &amp;lt;APP_KEY&amp;gt;:&amp;lt;APP_SECRET&amp;gt;");
		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\":\"/&amp;lt;ACCESS_CODE&amp;gt;\",\"grant_type\": \"authorization_code\"}");

        std::string buffer;

		curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
	    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &amp;amp;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();
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be appreciated, thank you.&lt;/P&gt;</description>
    <pubDate>Fri, 19 Jan 2024 16:10:40 GMT</pubDate>
    <dc:creator>pakk4</dc:creator>
    <dc:date>2024-01-19T16:10:40Z</dc:date>
    <item>
      <title>Error 404 when trying to get refresh token using CURL C++</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Error-404-when-trying-to-get-refresh-token-using-CURL-C/m-p/745571#M32798</link>
      <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;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 &amp;lt;APP_KEY&amp;gt;:&amp;lt;APP_SECRET&amp;gt;");
		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\":\"/&amp;lt;ACCESS_CODE&amp;gt;\",\"grant_type\": \"authorization_code\"}");

        std::string buffer;

		curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
	    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &amp;amp;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();
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be appreciated, thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jan 2024 16:10:40 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Error-404-when-trying-to-get-refresh-token-using-CURL-C/m-p/745571#M32798</guid>
      <dc:creator>pakk4</dc:creator>
      <dc:date>2024-01-19T16:10:40Z</dc:date>
    </item>
    <item>
      <title>Re: Error 404 when trying to get refresh token using CURL C++</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Error-404-when-trying-to-get-refresh-token-using-CURL-C/m-p/745605#M32799</link>
      <description>&lt;P&gt;Based on this code, it looks like you're not formatting this HTTP request correctly:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Make sure you're using the POST method (i.e., not GET)&lt;/LI&gt;
&lt;LI&gt;Send the parameters as application/x-www-form-urlencoded data in the request body, not as JSON in a Dropbox-API-Arg header&lt;/LI&gt;
&lt;LI&gt;When sending the app key/secret in the Authorization header, be sure to encode them with base64 encoding&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Please refer to &lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#oauth2-token" target="_blank"&gt;the /oauth2/token documentation here&lt;/A&gt; for information on how to configure this request.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jan 2024 19:54:40 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Error-404-when-trying-to-get-refresh-token-using-CURL-C/m-p/745605#M32799</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2024-01-19T19:54:40Z</dc:date>
    </item>
    <item>
      <title>Re: Error 404 when trying to get refresh token using CURL C++</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Error-404-when-trying-to-get-refresh-token-using-CURL-C/m-p/745627#M32800</link>
      <description>&lt;P&gt;Hi &lt;a href="https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/1795784"&gt;@pakk4&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Before trying to do something read carefully all relevant documents (i.e at least curllib and Dropbox API documentation), something you skipped as seems. 🙋&lt;/P&gt;&lt;P&gt;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!&lt;/P&gt;&lt;P&gt;Some pseudocode follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;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) -&amp;gt; size_t {
    std::string&amp;amp; 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&amp;amp;code=");
    body += "&amp;lt;your access code&amp;gt;";
    curl_easy_setopt(curl, CURLOPT_URL, oauth2_token);
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body.c_str());
    curl_easy_setopt(curl, CURLOPT_USERPWD, "&amp;lt;APP_KEY&amp;gt;:&amp;lt;APP_SECRET&amp;gt;");
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, callback);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&amp;amp;dataBuf);
    CURLcode res = curl_easy_perform(curl);
    curl_easy_cleanup(curl);
    
    // ... do whatever you want with your result here.
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Adapt it to your needs.&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jan 2024 23:31:34 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Error-404-when-trying-to-get-refresh-token-using-CURL-C/m-p/745627#M32800</guid>
      <dc:creator>Здравко</dc:creator>
      <dc:date>2024-01-19T23:31:34Z</dc:date>
    </item>
  </channel>
</rss>

