【发布时间】:2016-06-27 08:59:57
【问题描述】:
我正在尝试使用 Angular Js 导入用户的 gmail 联系人。该代码在纯 javascript 中运行良好,但在 angular js 中出现错误。
HTML 代码..
<a class="btn btn-primary btn-simple" ng-click="importgoogle()"><u>Import Gmail Friends</u></a>
角度代码..
var clientId = 'Client ID';
var scopes = 'https://www.googleapis.com/auth/contacts.readonly';
$scope.importgoogle = function(){
window.setTimeout(authorize); //calls authorize()
}
var authorize = function(){
gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: false}, handleAuthorization); //calls handleAuthorization()
}
var handleAuthorization = function(){
if (authorizationResult && !authorizationResult.error) {
$.get("https://www.google.com/m8/feeds/contacts/default/thin?alt=json&access_token=" + authorizationResult.access_token + "&max-results=500&v=3.0",
function(response){
console.log(response);
});
}
}
输入用户的 ID 和密码后,控制台中会显示以下错误消息..
Uncaught ReferenceError: authorizationResult is not defined
无法理解我哪里出错了,因为这段代码在 Javascript 中运行。请帮助..
【问题讨论】:
-
你确定是运行的代码吗?在这段代码中它不能得到这个错误。
-
也许你必须刷新/重新加载你的代码
标签: javascript angularjs google-api google-contacts-api