Recently, I successfully integrated the Google Picker API
into my project. This feature prompts a window for Google authentication
and then displays all the files stored in Google Drive.
However, I now have a specific requirement where I want to access these files without triggering the authentication popup. Instead, I intend to use the username and password that are already stored in my database.
Is there a method through which I can pass the user credentials, receive authorization, and access the files accordingly?
Here is a snippet of my code:
<script>
function onApiLoad() {
gapi.load('auth', { 'callback': onAuthApiLoad });
gapi.load('picker');
}
function onAuthApiLoad() {
window.gapi.auth.authorize({
'client_id': 'xxxx.apps.googleusercontent.com',
'scope': ['https://www.googleapis.com/auth/drive']
}, handleAuthResult);
}
var oauthToken;
function handleAuthResult(authResult) {
if (authResult && !authResult.error) {
oauthToken = authResult.access_token;
createPicker();
}
}
function createPicker() {
var picker = new google.picker.PickerBuilder()
.addView(new google.picker.DocsUploadView())
.addView(new google.picker.DocsView())
.setOAuthToken(oauthToken)
.setDeveloperKey('xxxx')
.enableFeature(google.picker.Feature.MULTISELECT_ENABLED)
.addView(new google.picker.VideoSearchView().setSite(google.picker.VideoSearchView.YOUTUBE))
.setCallback(pickerCallback)
.build();
picker.setVisible(true);
}
</script>