Я пытаюсь подключиться к интерфейсу API Google Drive, используя Firebase Auth.Я успешно сделал это в приложении, но не могу понять это в javascript.
var config = {
apiKey: "apikey",
authDomain: "xyz.firebaseapp.com",
databaseURL: "https://xyz.firebaseio.com",
clientId: 'clientid.apps.googleusercontent.com',
discoveryDocs: ['https://www.googleapis.com/discovery/v1/apis/drive/v3/rest'],
scope: 'https://www.googleapis.com/auth/drive'
};
if (!firebase.apps.length) {
firebase.initializeApp(config);
}
var provider = new firebase.auth.GoogleAuthProvider();
provider.addScope(config.scope);
var btn = document.getElementById("auth"); // Create a <button> element
btn.onclick = function () {
firebase.auth().signInWithPopup(provider).then(function (result) {
// This gives you a Google Access Token. You can use it to access the Google API.
var token = result.credential.accessToken;
result.drive.files.list({
'pageSize': 10,
'fields': "nextPageToken, files(id, name)"
}).then(function (response) {
appendPre('Files:');
var files = response.result.files;
if (files && files.length > 0) {
for (var i = 0; i < files.length; i++) {
var file = files[i];
appendPre(file.name + ' (' + file.id + ')');
}
} else {
appendPre('No files found.');
}
});
// The signed-in user info.
var user = result.user;
// ...
}).catch(function (error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// The email of the user's account used.
var email = error.email;
// The firebase.auth.AuthCredential type that was used.
var credential = error.credential;
// ...
});
};
document.body.appendChild(btn);
Это то, с чем я сейчас работаю, но я получаю отказ в доступе, даже если разрешениянастроить в консоли Google API.