无法使用嵌入在应用程序中的Javascript获取Google OAUTH access_令牌
标题:无法使用嵌入在应用程序中的Javascript获取Google誓言访问令牌 几天来,我一直在努力获取JavaScript中的Google誓言访问令牌值。最终,我想用它来进行谷歌分析,但现在我只希望登录我的谷歌账户。我在下面的邮政编码中看到了与我希望使用的非常接近的内容: 我的这个示例的实现运行时没有错误,但它无法获取访问令牌。有人能说明需要进行哪些调整才能获得访问权令牌值吗?这是我的JavaScript:无法使用嵌入在应用程序中的Javascript获取Google OAUTH access_令牌,javascript,google-api,google-oauth,google-analytics-api,Javascript,Google Api,Google Oauth,Google Analytics Api,标题:无法使用嵌入在应用程序中的Javascript获取Google誓言访问令牌 几天来,我一直在努力获取JavaScript中的Google誓言访问令牌值。最终,我想用它来进行谷歌分析,但现在我只希望登录我的谷歌账户。我在下面的邮政编码中看到了与我希望使用的非常接近的内容: 我的这个示例的实现运行时没有错误,但它无法获取访问令牌。有人能说明需要进行哪些调整才能获得访问权令牌值吗?这是我的JavaScript: // Module declaration. var myApp = angula
// Module declaration.
var myApp = angular.module('myApp', []);
var googleapi = {
authorize: function(options) {
console.log(options); // **** THIS WORKS.
var deferred = $.Deferred();
deferred.reject({ error: 'Not Implemented' });
return deferred.promise();
}
};
// Controller.
myApp.controller('MainController', ['$scope', function ($scope) {
$scope.greeting = "Hello";
$scope.call_google = function(){
console.log("inside call_google"); // **** THIS WORKS.
googleapi.authorize({
client_id: '108adf6o7nn.apps.googleusercontent.com',
client_secret: 'mySecret',
redirect_uri: 'http://localhost',
scope: 'https://www.googleapis.com/auth/userinfo.email'
}).done(function(data) { // **** THIS BLOCK IS NEVER ENTERED EVEN WHEN client_id is empty.
accessToken=data.access_token;
console.log(data.access_token);
});
};
}]);
这是我的HTML。我意识到将JQuery和AngularJS一起使用是一种膨胀,现在还可以。我主要关心的是能否在JavaScript中获得access_令牌
<!doctype html>
<html>
<head>
<title>Starting Angular</title>
</head>
<body ng-app="myApp">
<!-- Identify the controller and model to be used. -->
<div ng-controller="MainController" ng-init="call_google()">
<h1 ng-bind="greeting"></h1>
<br />
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js"> </script>
<script src="js/controllers.js"></script>
</body>
</html>
起始角
感谢您的帮助和见解。不确定这是否也有帮助,这是一个同样有用的替代方案:谢谢您的建议。我真的很感激。这些都是web应用程序的有效方法,但我的不是web应用程序。对于oauth,必须处理一系列请求和响应。我仍然希望使用来自各种客户端的JavaScript,我相信如果我能够获得access_令牌值,这种方法会起作用。我正在本地服务器上运行该示例,但计划从不同平台上的一系列客户端嵌入该示例,这些平台不使用web servers.PS。戴夫:谢谢你的编辑!