2017-10-13 4 views
0
var xhr = new XMLHttpRequest(); 
xhr.responseType = 'String'; 
xhr.onreadystatechange = function() { 
    if (xhr.readyState === 4 && xhr.status === 200) { 
    var response = xhr.response; 
    console.log(response); 
    } 
}; 
xhr.open('POST', 'https://api.dropboxapi.com/2/files/list_folder'); 
xhr.setRequestHeader('Authorization', 'Bearer ' + token); 
xhr.setRequestHeader('Content-Type', 'application/json'); 
xhr.setRequestHeader('Dropbox-API-Arg', JSON.stringify({ 
    path: '/lol' 
})); 
xhr.send(); 

Ich kann nicht herausfinden, was im Code falsch scheint. Irgendeine Hilfe?Dropbox list_folder api Javascript funktioniert nicht

+0

Was funktioniert nicht genau? Welche Antwort bekommst du? – Greg

Antwort

0

bei der Dokumentation der Suche nach list_folder - das Endpunkt ist ein RPC-Endpunkt:

Diese Endpunkte Argumente als JSON in der Anfrage Körper akzeptieren und zurückgehen als JSON im Antworttext. RPC-Endpunkte befinden sich in der Domäne api.dropboxapi.com.

Dropbox-API-Arg Header scheint für Content-upload und Content-download Typ Endpunkte

Ich sehe nicht genannt für /files/list_folder Endpunkt über einen Header benötigt Dropbox-API-Arg alles verwendet werden. Versuchen Sie etwas wie

xhr.open('POST', 'https://api.dropboxapi.com/2/files/list_folder'); 
xhr.setRequestHeader('Authorization', 'Bearer ' + token); 
xhr.setRequestHeader('Content-Type', 'application/json'); 
xhr.send(JSON.stringify({path:"/lol"})); 
Verwandte Themen