节点webkit和谷歌驱动api



试图让Google Drive API在node-webkit中工作。

发送身份验证消息时,会发送一个被拒绝的文件来源://。

https://accounts.google.com/o/oauth2/auth
?client_id=<some value>
&scope=https://www.googleapis.com/auth/drive.appdata
https://www.googleapis.com/auth/drive.file
https://www.googleapis.com/auth/drive
&immediate=true
&proxy=oauth2relay1232990068
&redirect_uri=postmessage
&origin=file://
&response_type=token
&state=1938150804|0.1319366391
&authuser=0

不知道为什么它是从gap以这种方式发送的——有人知道如何从node-webkit验证谷歌驱动器吗?

我选择绕过oAuth的API,自己做。

用户必须复制身份验证代码并将其粘贴到我的应用程序中——这不是第一选择,但他们只需要做一次,这比(缺乏)替代方案更可取。

为感兴趣的人共享代码:

当用户选择谷歌驱动器:

            window.open('https://accounts.google.com/o/oauth2/auth?'
                    + 'client_id=<some value>'
                    + '&scope=<space delimited list of permissions>'
                    + '&redirect_uri=urn:ietf:wg:oauth:2.0:oob'
                    + '&response_type=code');

这会产生一个弹出窗口,让他们允许并向他们提供身份验证代码。

当身份验证代码粘贴到我的应用程序中时,我将其保存到DB并继续获取访问代码,然后将其保存至DB:

            $.ajax({
                url: "https://accounts.google.com/o/oauth2/token",
                type: 'post',
                data: {
                    code: <authCode>,
                    client_id: CLIENT_ID,
                    client_secret: CLIENT_SECRET,
                    redirect_uri: 'urn:ietf:wg:oauth:2.0:oob',
                    grant_type: 'authorization_code'
                }
            }).error(function(data) {
                myObj.isAuth = false;
                if (cbFail) {
                    cbFail(data);
                }
            }).success(function(data) {
                myObj.isAuth = true;
                <persist entire response>
                if (cbSuccess) {
                    cbSuccess();
                }
            });

最新更新