<?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 Dropbox API, I can't upload a file to Dropbox (err. 401 Unauthorized) in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Dropbox-API-I-can-t-upload-a-file-to-Dropbox-err-401/m-p/637609#M29374</link>
    <description>&lt;P&gt;Please, help: I can't upload a file to Dropbox (err. 401 Unauthorized)&lt;/P&gt;&lt;P&gt;I am using Delphi XE3, Indy THttp component. Please, can you look at the header and body of the message being sent to see if there is an error?&lt;BR /&gt;I got AccessToken on&lt;BR /&gt;&lt;A href="https://dropbox.github.io/dropbox-api-v2-explorer/#auth_token/from_oauth1" target="_self"&gt;https://dropbox.github.io/dropbox-api-v2-explorer/#auth_token/from_oauth1&lt;/A&gt;&amp;nbsp;&lt;BR /&gt;I assume it's persistent and I don't need to retrieve it every time I access it&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;const
API_URL = 'https://content.dropboxapi.com/2/files/upload';
cFile = 'D:\my_file_path_on_pc\testfile.txt';
cook
wAccessToken : string;
Source: TFileStream;
IdHTTP: TIdHTTP;
Res, OpenSSLpath, wVal : string;
Ssl: TIdSSLIOHandlerSocketOpenSSL;
begin
wAccessToken := '_my_access_token_';
Source := TFileStream.Create(cFile, fmOpenRead);
...
...
IdHTTP.Request.CustomHeaders.Values['Authorization'] := 'Bearer ' + wAccessToken;
IdHTTP.Request.CustomHeaders.Values['Dropbox-API-Arg'] :=
'{ "autorename": false, "mode": "add", "mute": false, "path": "/CUZK/test.txt", "strict_conflict": false }';
IdHTTP.Request.CustomHeaders.Values['Content-Type'] := 'application/octet-stream';

Res := IdHTTP.Post(API_URL, Source);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 18 Nov 2022 11:20:32 GMT</pubDate>
    <dc:creator>Polas</dc:creator>
    <dc:date>2022-11-18T11:20:32Z</dc:date>
    <item>
      <title>Dropbox API, I can't upload a file to Dropbox (err. 401 Unauthorized)</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Dropbox-API-I-can-t-upload-a-file-to-Dropbox-err-401/m-p/637609#M29374</link>
      <description>&lt;P&gt;Please, help: I can't upload a file to Dropbox (err. 401 Unauthorized)&lt;/P&gt;&lt;P&gt;I am using Delphi XE3, Indy THttp component. Please, can you look at the header and body of the message being sent to see if there is an error?&lt;BR /&gt;I got AccessToken on&lt;BR /&gt;&lt;A href="https://dropbox.github.io/dropbox-api-v2-explorer/#auth_token/from_oauth1" target="_self"&gt;https://dropbox.github.io/dropbox-api-v2-explorer/#auth_token/from_oauth1&lt;/A&gt;&amp;nbsp;&lt;BR /&gt;I assume it's persistent and I don't need to retrieve it every time I access it&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;const
API_URL = 'https://content.dropboxapi.com/2/files/upload';
cFile = 'D:\my_file_path_on_pc\testfile.txt';
cook
wAccessToken : string;
Source: TFileStream;
IdHTTP: TIdHTTP;
Res, OpenSSLpath, wVal : string;
Ssl: TIdSSLIOHandlerSocketOpenSSL;
begin
wAccessToken := '_my_access_token_';
Source := TFileStream.Create(cFile, fmOpenRead);
...
...
IdHTTP.Request.CustomHeaders.Values['Authorization'] := 'Bearer ' + wAccessToken;
IdHTTP.Request.CustomHeaders.Values['Dropbox-API-Arg'] :=
'{ "autorename": false, "mode": "add", "mute": false, "path": "/CUZK/test.txt", "strict_conflict": false }';
IdHTTP.Request.CustomHeaders.Values['Content-Type'] := 'application/octet-stream';

Res := IdHTTP.Post(API_URL, Source);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2022 11:20:32 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Dropbox-API-I-can-t-upload-a-file-to-Dropbox-err-401/m-p/637609#M29374</guid>
      <dc:creator>Polas</dc:creator>
      <dc:date>2022-11-18T11:20:32Z</dc:date>
    </item>
    <item>
      <title>Re: Dropbox API, I can't upload a file to Dropbox (err. 401 Unauthorized)</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Dropbox-API-I-can-t-upload-a-file-to-Dropbox-err-401/m-p/637659#M29375</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/1592630"&gt;@Polas&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;...&lt;BR /&gt;I assume it's persistent and I don't need to retrieve it every time I access it&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Hi &lt;a href="https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/1592630"&gt;@Polas&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;That's the mistake of you. In spite some time ago was possible to receive long lived access token, it's not possible anymore. You can still use available long lived access token if you have one (in the way you are trying to), but new one cannot be issued; all new tokens are short lived with validity period 4 hours, at most. For long term access you need refresh token and "refreshing" the access token every time it expires you have long term access access &lt;img class="lia-deferred-image lia-image-emoji" src="https://www.dropboxforum.com/html/@41457EF40051AFF130FDBFE21B496926/emoticons/1f609.png" alt=":winking_face:" title=":winking_face:" /&gt;. You can take a look &lt;A href="https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Issue-in-generating-access-token/m-p/592921/highlight/true#M27586" target="_blank" rel="noopener"&gt;here&lt;/A&gt; how you may organize your applications work. Refresh token doesn't expire automatically and alive until explicit revoke from either the application itself or user using your application.&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2022 13:00:26 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Dropbox-API-I-can-t-upload-a-file-to-Dropbox-err-401/m-p/637659#M29375</guid>
      <dc:creator>Здравко</dc:creator>
      <dc:date>2022-11-18T13:00:26Z</dc:date>
    </item>
    <item>
      <title>Re: Dropbox API, I can't upload a file to Dropbox (err. 401 Unauthorized)</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Dropbox-API-I-can-t-upload-a-file-to-Dropbox-err-401/m-p/637734#M29383</link>
      <description>&lt;P&gt;&lt;a href="https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/1592630"&gt;@Polas&lt;/a&gt; Здравко is correct; new Dropbox access tokens are not persistent. Dropbox is no longer offering the option for creating new long-lived access tokens. Dropbox is switching to only issuing short-lived access tokens (and optional refresh tokens) instead of long-lived access tokens. You can find &lt;A href="https://dropbox.tech/developers/migrating-app-permissions-and-access-tokens#updating-access-token-type" target="_blank" rel="noopener noreferrer"&gt;more information on this migration here&lt;/A&gt;.&lt;BR /&gt;&lt;BR /&gt;Apps can still get long-term access by requesting "offline" access though, in which case the app receives a "refresh token" that can be used to retrieve new short-lived access tokens as needed, without further manual user intervention. You can find more information in the &lt;A href="https://developers.dropbox.com/oauth-guide" target="_blank" rel="noopener noreferrer"&gt;OAuth Guide&lt;/A&gt; and &lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#authorization" target="_blank" rel="noopener noreferrer"&gt;authorization documentation&lt;/A&gt;. There's a basic outline of processing this flow in &lt;A href="https://dropbox.tech/developers/using-oauth-2-0-with-offline-access" target="_blank" rel="noopener noreferrer"&gt;this blog post&lt;/A&gt; which may serve as a useful example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And for debugging issues like this, you should print out the HTTPS response body, as it should contain a more useful error message (such as 'invalid_access_token' or 'expired_access_token'). You may need to refer to the documentation for your network client for information on how to access the response body.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2022 18:43:29 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Dropbox-API-I-can-t-upload-a-file-to-Dropbox-err-401/m-p/637734#M29383</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2022-11-18T18:43:29Z</dc:date>
    </item>
  </channel>
</rss>

