<?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: embed latest image from Dropbox folder to website in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/embed-latest-image-from-Dropbox-folder-to-website/m-p/725803#M32067</link>
    <description>&lt;P&gt;&lt;a href="https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/1761954"&gt;@CASU&lt;/a&gt; As Здравко said, please share the information about what isn't working as expected for you. For instance, include relevant error messages, etc. Be sure to always check the response body for your API calls, as it may contain an error message.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, note that using "dl.dropboxusercontent.com" in shared links is not officially supported. Please refer to &lt;A href="https://help.dropbox.com/share/force-download" target="_blank"&gt;this help article&lt;/A&gt; for information on the supported parameters.&lt;/P&gt;</description>
    <pubDate>Tue, 31 Oct 2023 15:41:00 GMT</pubDate>
    <dc:creator>Greg-DB</dc:creator>
    <dc:date>2023-10-31T15:41:00Z</dc:date>
    <item>
      <title>embed latest image from Dropbox folder to website</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/embed-latest-image-from-Dropbox-folder-to-website/m-p/725686#M32063</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope somebody can help. I'm trying to embed the latest image from Dropbox to a website. Unfortunately I can't get the script right. If anyone can help with the script it would be great.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;Display Latest Dropbox Image&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;div id="image-container"&amp;gt;
        &amp;lt;img id="latest-image" src="" alt="Latest Image"&amp;gt;
    &amp;lt;/div&amp;gt;

    &amp;lt;script&amp;gt;
        const folderPath = '/home/Snapshots'; // Replace with the folder path in Dropbox

        // Function to update the displayed image
        async function updateImage() {
            try {
                // Fetch the list of files in the folder
                const response = await fetch('https://api.dropboxapi.com/2/files/list_folder', {
                    method: 'POST',
                    headers: {
                        'Authorization': 'Bearer sl.BoQurVyU8dwp1VT5dXxRehp24GQBr8SEsOxXzDvFswQpVl9y_LOV2zA-oNUPVR5nRy1vntHjPG8KKPxahEJ-xj_kq5ksKSGKOJMCFZtNzkyS_BGbnGD4cg5tgQ4VQcP_OErglltNHrfu', // Replace with your Dropbox access token
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify({
                        path: folderPath,
                    }),
                });

                const data = await response.json();

                if (data.entries.length === 0) {
                    console.log('No image files found in the folder.');
                    return;
                }

                // Find the latest image file
                const latestImage = data.entries.reduce((prev, current) =&amp;gt; (prev.client_modified &amp;gt; current.client_modified) ? prev : current);

                // Get the direct image URL from the shared link
                const sharedLinkResponse = await fetch('https://api.dropboxapi.com/2/sharing/create_shared_link_with_settings', {
                    method: 'POST',
                    headers: {
                        'Authorization': 'Bearer sl.BoQurVyU8dwp1VT5dXxRehp24GQBr8SEsOxXzDvFswQpVl9y_LOV2zA-oNUPVR5nRy1vntHjPG8KKPxahEJ-xj_kq5ksKSGKOJMCFZtNzkyS_BGbnGD4cg5tgQ4VQcP_OErglltNHrfu', // Replace with your Dropbox access token
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify({
                        path: latestImage.path_display,
                    }),
                });

                const sharedLinkData = await sharedLinkResponse.json();
                const latestImageURL = sharedLinkData.url.replace('www.dropbox.com', 'dl.dropboxusercontent.com');

                const image = document.getElementById('latest-image');
                image.src=latestImageURL;
            } catch (error) {
                console.error('Error:', error);
            }
        }

        // Initial image update
        updateImage();

        // Refresh the image every X milliseconds (e.g., every 30 seconds)
        const refreshInterval = 30000; // 30 seconds
        setInterval(updateImage, refreshInterval);
    &amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The App permissions are set for&amp;nbsp;&lt;SPAN&gt;"files.metadata.read" and "files.content.read".&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I'm struggling for a couple of days now. If anyone can help with the script would be great.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Kind regards,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Jeroen&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2023 09:59:37 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/embed-latest-image-from-Dropbox-folder-to-website/m-p/725686#M32063</guid>
      <dc:creator>CASU</dc:creator>
      <dc:date>2023-10-31T09:59:37Z</dc:date>
    </item>
    <item>
      <title>Re: embed latest image from Dropbox folder to website</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/embed-latest-image-from-Dropbox-folder-to-website/m-p/725770#M32064</link>
      <description>&lt;P&gt;Hi &lt;a href="https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/1761954"&gt;@CASU&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;I can try speculate what's wrong with your code, but it's always better when you're saying what's going wrong - unexpected output, error messages, etc.&lt;/P&gt;&lt;P&gt;First do you make somehow sure that every 30 seconds you will have new 'latest image' without existing link? 🧐 If no, when you're going to create new one, you will receive an error showing that there is already a link! You didn't handle this in any way. If I have to bet, this is the issue. If I'm wrong, please clarify.&lt;/P&gt;&lt;P&gt;You can take a look &lt;A href="https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Downloading-large-amount-of-files-to-my-web-application/m-p/725217/highlight/true#M3724" target="_blank" rel="noopener"&gt;here&lt;/A&gt; for an example with different main target, but showing how you can get a link in a safe way. It's in Python, but still shows the idea, so you can easy 'translate' it to JavaScript, I believe. &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;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS: Something else, I didn't mention, but important if your code isn't just a draft: All access tokens are short lived (there are still confusing old descriptions)!!! So in production, for long term use, you need either dynamic re-authentication or refresh token. &lt;img class="lia-deferred-image lia-image-emoji" src="https://www.dropboxforum.com/html/@43936046666A7399861DC821652B665A/emoticons/1f608.png" alt=":smiling_face_with_horns:" title=":smiling_face_with_horns:" /&gt; A bit complication of the code - complication that you can avoid using SDK (to some extent).&lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2023 13:42:56 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/embed-latest-image-from-Dropbox-folder-to-website/m-p/725770#M32064</guid>
      <dc:creator>Здравко</dc:creator>
      <dc:date>2023-10-31T13:42:56Z</dc:date>
    </item>
    <item>
      <title>Re: embed latest image from Dropbox folder to website</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/embed-latest-image-from-Dropbox-folder-to-website/m-p/725803#M32067</link>
      <description>&lt;P&gt;&lt;a href="https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/1761954"&gt;@CASU&lt;/a&gt; As Здравко said, please share the information about what isn't working as expected for you. For instance, include relevant error messages, etc. Be sure to always check the response body for your API calls, as it may contain an error message.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, note that using "dl.dropboxusercontent.com" in shared links is not officially supported. Please refer to &lt;A href="https://help.dropbox.com/share/force-download" target="_blank"&gt;this help article&lt;/A&gt; for information on the supported parameters.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2023 15:41:00 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/embed-latest-image-from-Dropbox-folder-to-website/m-p/725803#M32067</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2023-10-31T15:41:00Z</dc:date>
    </item>
  </channel>
</rss>

