最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Develop Chrome extension without redirect URI - Stack Overflow

programmeradmin1浏览0评论

I am developing a Chrome extension that is a forked open-source program on Github. 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!

I am developing a Chrome extension that is a forked open-source program on Github.. 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!

Share Improve this question edited Mar 22, 2014 at 22:45 Sam R. 16.4k14 gold badges73 silver badges125 bronze badges asked Feb 25, 2013 at 22:08 chaohuangchaohuang 4,1154 gold badges32 silver badges36 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 2

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.

You can just use: http://localhost it should be fine.

This biggest thing is getting your fingerprint and then API Key.

There is a speicial URI that that you could register:

https://<extension-id>.chromiumapp/<anything-here>

The browser would catch the redirect and trigger your code, instead of really go to the URL.

Please see more details here:

https://developer.chrome./apps/app_identity#register_provider

Note that you extension ID must be fixed in this case.

发布评论

评论列表(0)

  1. 暂无评论