简体   繁体   中英

Can't create share link using dropbox javascript sdk

I'm trying to create a shareable link using dropbox api, but the function that I used doesn't return anything.

 var ACCESS_TOKEN = "access_token";
 var SHARED_LINK = "/example/example.doc";
 var dbx = new Dropbox({ accessToken: ACCESS_TOKEN });
 var x = dbx.SharingCreateSharedLink({path: SHARED_LINK});
 alert(x);

The Dropbox JavaScript SDK returns the API call results asynchronously, not in the return value of the method call.

You can see an example of how to set up the callbacks for the result and error, using then and catch , respectively, here:

https://github.com/dropbox/dropbox-sdk-js/blob/master/examples/javascript/basic/index.html#L54

So, for example, your code should look something like this:

var ACCESS_TOKEN = "access_token";
var filePath = "/example/example.doc";

var dbx = new Dropbox({ accessToken: ACCESS_TOKEN });
dbx.sharingCreateSharedLinkWithSettings({path: filePath})
.then(function(response) {
   console.log(response);
 })
 .catch(function(error) {
   console.log(error);
 });

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