如何让 Google 联系人 API 与 AngularJS 一起工作?
How to make Google Contact API work with AngularJS?
我一直在尝试从响应中获取数据并将其添加到控制器,但没有成功。
这是我的previous question。
AngularJS是怎么做的?
我使用的代码是这样的:
invitePeersController.getGmailContacts = function(){
console.log("I come in gmail contacts");
var clientId = "contact key";
var apiKey = "apiKey";
var scopes = "https://www.googleapis.com/auth/contacts.readonly";
authorize();
function authorize() {
gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: false}, handleAuthorization);
}
function handleAuthorization(authorizationResult){
invitePeersController.gmailContacts = [];
var gmailData = [];
if (authorizationResult && !authorizationResult.error){
var urlContact = "https://www.google.com/m8/feeds/contacts/default/thin?alt=json&access_token=" + authorizationResult.access_token + "&max-results=50000&v=3.0";
var promiseGoogleData = HttpService.httpGetExternalLink(urlContact);
promiseGoogleData.then(function (response) {
var jsonChildData = response.data.feed.entry;
for(var i=0; i<jsonChildData.length ;i++){
var item = {};
try{
var name = jsonChildData[i].title.$t;
var email = jsonChildData[i].gd$email[0].address;
if(name.substring(1, name.length-1) && email.substring(1, email.length-1)){
item ["name"] = name.substring(1, name.length-1);
item ["email"] = email.substring(1, email.length-1);
item ["id"] = email.substring(1, email.length-1).replace(/[^a-zA-Z ]/g, "");
invitePeersController.gmailContacts.push(item);
gmailData.push(item);
}
}catch(error){
console.log("Error is thrown while trying to read gmail resposne");
}
}
$state.go("app.inviteContacts");
InvitePeersService.setGmailContactsData( invitePeersController.gmailContacts);
return response;
})
.catch(function (error) {
console.log("Something went terribly wrong while trying to get Gmail Data.");
});
}
}
}
另外不要忘记在凭据中添加域名:
我一直在尝试从响应中获取数据并将其添加到控制器,但没有成功。
这是我的previous question。
AngularJS是怎么做的?
我使用的代码是这样的:
invitePeersController.getGmailContacts = function(){
console.log("I come in gmail contacts");
var clientId = "contact key";
var apiKey = "apiKey";
var scopes = "https://www.googleapis.com/auth/contacts.readonly";
authorize();
function authorize() {
gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: false}, handleAuthorization);
}
function handleAuthorization(authorizationResult){
invitePeersController.gmailContacts = [];
var gmailData = [];
if (authorizationResult && !authorizationResult.error){
var urlContact = "https://www.google.com/m8/feeds/contacts/default/thin?alt=json&access_token=" + authorizationResult.access_token + "&max-results=50000&v=3.0";
var promiseGoogleData = HttpService.httpGetExternalLink(urlContact);
promiseGoogleData.then(function (response) {
var jsonChildData = response.data.feed.entry;
for(var i=0; i<jsonChildData.length ;i++){
var item = {};
try{
var name = jsonChildData[i].title.$t;
var email = jsonChildData[i].gd$email[0].address;
if(name.substring(1, name.length-1) && email.substring(1, email.length-1)){
item ["name"] = name.substring(1, name.length-1);
item ["email"] = email.substring(1, email.length-1);
item ["id"] = email.substring(1, email.length-1).replace(/[^a-zA-Z ]/g, "");
invitePeersController.gmailContacts.push(item);
gmailData.push(item);
}
}catch(error){
console.log("Error is thrown while trying to read gmail resposne");
}
}
$state.go("app.inviteContacts");
InvitePeersService.setGmailContactsData( invitePeersController.gmailContacts);
return response;
})
.catch(function (error) {
console.log("Something went terribly wrong while trying to get Gmail Data.");
});
}
}
}
另外不要忘记在凭据中添加域名: