I am developing a Chrome extension that is a forked open-source program on Github.com. The extension needs the Google Drive API, which requires an OAuth 2.0 client ID. However, during the creation of the client ID, it requires me to provide a redirect URI, but I don't have any redirect domain. Does this mean I cannot use the Google Drive API or is there a workaround?
Thanks!
Yes, you can use Drive API but you have to use Google JS client just provide scope, client id, client secret and load js client and make API calls. But in JavaScript origin there must be your chrome extension id (chrome-extension://abcdefghijklmnopqrstuvwxyx)
below functions can be handy for you
// on client load call this function
var handleClientLoadAuto = function () {
gapi.client.setApiKey(apiKey);
window.setTimeout(checkAuthAuto, 1);
}
and
var checkAuthAuto = function () {
gapi.auth.authorize({
client_id: clientId,
scope: 'scope here',
immediate: true
}, handleAuthResultAuto);
}
and if everything is OK:
var handleAuthResultAuto = function (authResult) {
if (authResult && !authResult.error) {
//do call to drive api using
gapi.client.load('drive', 'v2', function () {
var request = gapi.client.drive.files.list(params);
request.execute(function (resp) {
if (resp && resp.error) {
//call to error callback function
//handleError(resp);
} else {
//ok response
}
});
}
} else {}
}
But to use this you must be logged in otherwise it will not detect the authorization.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With