google-drive-api - Node-webkit 和 google drive api

标签 google-drive-api google-oauth node-webkit

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

发送 auth 消息时,它会与 File://的来源一起发送,但被拒绝。

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

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

最佳答案

我选择绕过 oAuth 的 API 并自己完成。

用户必须复制授权码并将其粘贴到我的应用程序中 - 不是首选,但他们只需要做一次,并且比(缺乏)替代方案更可取。

有兴趣的 friend 分享一下代码:

当用户选择 Google Drive 时:

            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();
                }
            });

关于google-drive-api - Node-webkit 和 google drive api,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20179343/

相关文章:

oauth - 用户之前已通过身份验证时,如何在 Firebase 中强制弹出 Google OAuth 弹出窗口?

r - 努力在 shinyapps.io 中使用我自己的 API key 和 googlesheets4

javascript - 不同窗口的Node-Webkit启动函数

node.js - require() 不适用于 node-webkit 6.0

node.js - 在 node.js 应用程序和 lua 应用程序之间共享数据

javascript - 在 Google API 调用中指定请求正文(使用 Google APIs Client Library for JavaScript)

node.js - 使用服务帐户 key 列出来自谷歌驱动器的公开共享文件未获取公共(public)文件

python - 刷新access token报 "invalid_grant"错误的情况?

javascript - 将文件夹上传到 GDrive 并获取用于上传文件的文件夹 ID

google-api - Google Drive API 控制台 : Error saving Drive UI integration page