<?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 Re: Python: Example of full OAuth2 flow with refresh in Discuss Dropbox Developer &amp; API</title>
    <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Python-Example-of-full-OAuth2-flow-with-refresh/m-p/749053#M3911</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/1798515"&gt;@donaldm314&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;3. There is no need to use the access token.&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/1798515"&gt;@donaldm314&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;In general Yes, you don't need to use access token explicitly when initialize your client object on any Dropbox SDK (including Python). The client object takes care to take access token alone/unassisted once initialized properly. Just to avoid confusion - API always needs access token, but SDK takes care for that in such cases.&lt;/P&gt;&lt;P&gt;Depending on what's the usage profile of your application just a proper object initialization with refresh token only may be enough (in cases when typically your application runs for long time and relatively rare reinitialized). In opposite situation (when your application runs as a command line, for instance, and the client object life is relatively short with few real API calls), it may be useful to keep track of the access token in use. In such a way you avoid too often refreshing that may affect your application performance. Example of such an use case (all together - OAuth flow, authentication save, and real calls) can be seen &lt;A href="https://www.dropboxforum.com/t5/Create-upload-and-share/How-can-a-script-or-app-get-a-shareable-Dropbox-link/m-p/680928/highlight/true#M68463" target="_blank" rel="noopener"&gt;here&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;</description>
    <pubDate>Sun, 04 Feb 2024 22:20:42 GMT</pubDate>
    <dc:creator>Здравко</dc:creator>
    <dc:date>2024-02-04T22:20:42Z</dc:date>
    <item>
      <title>Python: Example of full OAuth2 flow with refresh</title>
      <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Python-Example-of-full-OAuth2-flow-with-refresh/m-p/749029#M3910</link>
      <description>&lt;P&gt;Hi folks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been working on a Python script to read information from my Dropbox account. The&amp;nbsp;&lt;A href="https://github.com/dropbox/dropbox-sdk-python/tree/main/example/oauth" target="_blank" rel="noopener"&gt;Dropbox OAuth SDK examples&lt;/A&gt;&amp;nbsp;only demonstrate the initial part of the flow and do not use the refresh token.&amp;nbsp;I could not find a working example despite searching the Internet (and this forum).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After a bit of trial-and-error, I have a posted working example on GitHub: &lt;A href="https://github.com/donaldm314/dropbox-commandline-oauth-refresh" target="_self"&gt;Dropbox Command-line OAuth with Refresh&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Once the user has authorized Dropbox access, the script saves the resulting refresh token in .env. Subsequent executions of the script do not require any user intervention -- the refresh token is used instead.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The key bits I learned along the way:&lt;/P&gt;&lt;P&gt;1. This is sufficient to obtain an initial refresh token:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;    flow = DropboxOAuth2FlowNoRedirect(
        APP_KEY,
        APP_SECRET,
        token_access_type="offline"
    )&lt;/LI-CODE&gt;&lt;P&gt;2. Once the refresh token has been obtained, this is sufficient to access Dropbox:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;    with dropbox.Dropbox(
        app_key=APP_KEY,
        app_secret=APP_SECRET,
        oauth2_refresh_token=refresh_token
    ) as dbx:&lt;/LI-CODE&gt;&lt;P&gt;3. There is no need to use the access token.&lt;/P&gt;</description>
      <pubDate>Sun, 04 Feb 2024 17:54:03 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Python-Example-of-full-OAuth2-flow-with-refresh/m-p/749029#M3910</guid>
      <dc:creator>donaldm314</dc:creator>
      <dc:date>2024-02-04T17:54:03Z</dc:date>
    </item>
    <item>
      <title>Re: Python: Example of full OAuth2 flow with refresh</title>
      <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Python-Example-of-full-OAuth2-flow-with-refresh/m-p/749053#M3911</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/1798515"&gt;@donaldm314&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;3. There is no need to use the access token.&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/1798515"&gt;@donaldm314&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;In general Yes, you don't need to use access token explicitly when initialize your client object on any Dropbox SDK (including Python). The client object takes care to take access token alone/unassisted once initialized properly. Just to avoid confusion - API always needs access token, but SDK takes care for that in such cases.&lt;/P&gt;&lt;P&gt;Depending on what's the usage profile of your application just a proper object initialization with refresh token only may be enough (in cases when typically your application runs for long time and relatively rare reinitialized). In opposite situation (when your application runs as a command line, for instance, and the client object life is relatively short with few real API calls), it may be useful to keep track of the access token in use. In such a way you avoid too often refreshing that may affect your application performance. Example of such an use case (all together - OAuth flow, authentication save, and real calls) can be seen &lt;A href="https://www.dropboxforum.com/t5/Create-upload-and-share/How-can-a-script-or-app-get-a-shareable-Dropbox-link/m-p/680928/highlight/true#M68463" target="_blank" rel="noopener"&gt;here&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;</description>
      <pubDate>Sun, 04 Feb 2024 22:20:42 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Python-Example-of-full-OAuth2-flow-with-refresh/m-p/749053#M3911</guid>
      <dc:creator>Здравко</dc:creator>
      <dc:date>2024-02-04T22:20:42Z</dc:date>
    </item>
  </channel>
</rss>

