简体   繁体   中英

How to use Dropbox API to get most recent file in Github pages site

I'm currently trying to use the Dropbox API in a Github pages website to get the most recent file in Dropbox and use the title of it to change CSS background color. However, I can't seem to figure out how to write the js to use the Dropbox API. I have the access token which I have replaced with Insert_Access_Token_Here in the code I provided. The code below is a test that should print my files in the console, but doesn't. Can someone give me a clear way, from scratch, how I can use the Dropbox API to at least get the name of the most recent file. (Can I import Dropbox api using cdn cloudflaire?) Thank you

<script type="module" >
      import { Dropbox } from '../node_modules/dropbox';
      const dbx = new Dropbox({
        accessToken: 'Insert_Access_Token_Here',
        fetch
      })
      dbx.filesListFolder({
        path: ''
      }).then(res => console.log(res))
</script>

The error message I keep getting in the console is

net::ERR_ABORTED 404

I want to leave this here because it might help some other people who were confused by the API, but I figured it out. You can use

<script src="https://cdnjs.cloudflare.com/ajax/libs/dropbox.js/4.0.30/Dropbox-sdk.js" integrity="sha256-B2oONvdKJ3qkdcGzlVZwhFz55Pk6/+clzI+9hbK1C24=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fetch/2.0.3/fetch.js"></script>

in the <head> tag, and then under <script> in <body> you can put

var dbx = new Dropbox.Dropbox({ accessToken: 'Enter_Access_Token_Here' });

and you're good to go to use API commands.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM