在文件系统中使用谷歌API
Using google APIs in the file system?
您必须在 Google 开发者控制台中设置 javascript origins 以允许某些 origin 访问 google API。问题是我正在制作一个在使用 file://协议的node-webkit中运行的应用程序,而google不允许 file://成为javascript的起源。有什么解决方法吗?我尝试在node-webkit中运行本地http服务器,但这不起作用。
好吧,
您可以使用 http://127.0.0.1/或本地主机URL在Google Console上注册API,但在客户端将侦听器附加到浏览器的窗口,这样当Google api重定向到我们的终端时,我们可以拦截该操作并从URL获取Authorization Code
。我已经在phonegap/cordova应用程序上尝试过这个,它工作得很好。检查代码库以供参考。
var authUrl = AUTH_URL + '?' +
'&client_id=' + options.client_id +
'&redirect_uri=' + options.redirect_uri +
'&response_type=code' +
'&scope=' + options.scopez +
'&approval_prompt=force';
//Open the OAuth consent page in the InAppBrowser
var authWindow = window.open(authUrl, '_blank', 'location=no,toolbar=no,clearcache=yes,clearsessioncache=yes,closebuttoncaption="Close"');
authWindow.addEventListener('loadstart', function(e) {
var url = e.url;
var code = /'?code=(.+)$/.exec(url);
var error = /'?error=(.+)$/.exec(url);
//alert("code : " + JSON.stringify(code));
if (code || error) {
//Always close the browser when match is found
console.log("code : " + code);
console.log("Closing OAuth Window.");
authWindow.close();
}
if (code) {
//Exchange the authorization code for an access token
OAuthService.getAccessTokenByCode(code[1]).then(function(data) {
deferred.resolve(data);
}, function(error) {
deferred.reject(error);
});
} else if (error) {
//The user denied access to the app
deferred.reject({
error: error[1]
});
}
});
相关文章:
- 三星智能电视应用程序使用谷歌API
- 在谷歌api v3中使用地理自动完成功能获取邮政编码
- 从谷歌API地理代码的形式字段到数据库
- 从名称或邮政编码获取纬度和经度-谷歌API
- 英国邮政编码谷歌API不返回街道地址
- 用于谷歌API的Jquery
- 根据谷歌 Api v3 书/也用一个按钮添加一个标记
- 谷歌 API :仪表动画
- (谷歌API)单元格引用中的动态工作表和工作表创建脚本的名称
- 谷歌APi 不检索值
- 一个回调两个异步函数,一个是谷歌 api getDistanceMatrix
- 谷歌API正在计算无效地址的距离
- 在文件系统中使用谷歌API
- 如何对谷歌 API 搜索查询进行编码
- 如何使用谷歌API从街景切换到路线图
- 谁能告诉我为什么我不能从谷歌 API 获得城市列表
- 如何使用谷歌 API 网页版从address_components获取地点 ID
- 从经度和纬度谷歌 API 获取邮政编码
- 动态向下面的透视柱形图添加注释 - 谷歌 API
- 谷歌 API 图表日志刻度不起作用