javascript - Develop Chrome extension without redirect URI - Stack Overflow

I am developing a Chrome extension that is a forked open-source program on Github. The extension needs

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745546860a4632375.html

相关推荐

  • javascript - Develop Chrome extension without redirect URI - Stack Overflow

    I am developing a Chrome extension that is a forked open-source program on Github. The extension needs

    21小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信