Your workflow is unique 👨💻 - tell us how you use Dropbox here.
Forum Discussion
Hein B.
11 years agoNew member | Level 1
can't authenticate with javascript
I try to use the datastore API with javascript. This is my Code:
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<meta charset="UTF-8">
</head>
<body>
<script src="https://www.dropbox.com/static/api/dropbox-datastores-1.2-latest.js" type="text/javascript"></script>
<script>
var client = new Dropbox.Client({key: 'xxxxxxxxxxxx' });
// Try to finish OAuth authorization.
client.authenticate({interactive: false}, function (error) {
if (error) {
alert('Authentication error: ' + error);
}
});
alert(client.isAuthenticated());
if (client.isAuthenticated()) {
// Client is authenticated. Display UI.
}
</script>
</body>
</html>
The line alert(client.isAuthenticated()); always gives false which means that something went wrong with the authentication. Can someon tell me what I'm doing wrong?
3 Replies
Replies have been turned off for this discussion
- Steve M.11 years ago
Dropbox Staff
The code I see here should all work once authentication has been started, but I don't see a call to start authentication.
Somewhere (e.g. on a button click) should be a call to
client.authenticate(function (error) { ... });(no{ interactive: false }). That will start the authentication flow, and then when the user returns to the page, your existing code should finish the auth process.For an example, see https://www.dropbox.com/developers/datastore/tutorial/js#linking-accounts.
- Hein B.11 years agoNew member | Level 1
Why should I use a button to authenticate? I copied the code from the page that you have linked to and it should work fine. Do I have to do anything else to start authentication or does it suffice to call the method call client.authenticate?
- Steve M.11 years ago
Dropbox Staff
You don't need to call
client.authenticatefrom a button handler (unless you're using a popup, which will get blocked unless invoked from a user action), but it's the typical way to build an app.You don't need to do anything other than call
client.authenticate(without{ interactive: false }) to start the authentication process. I'd suggest following the tutorial exactly until you get working code.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!