如何获取登录用户的所有联系人,我添加了访问谷歌联系人的请求权限
requestPermissions: {
facebook: ['email', 'user_friends','read_friendlists'],
google:['https://www.google.com/m8/feeds']
},
我不知道如何访问联系人,我尝试用谷歌搜索,但我对结果感到困惑。
有人知道怎么做吗?
谁能告诉我答案?
非常感谢任何帮助
最佳答案
我刚刚使用了 google-contacts
大气包并在服务器端编写了以下函数,它对我有用
var opts= { email: Meteor.user().services.google.email,
consumerKey: "APIKEY",
consumerSecret: "APPSECRET",
token: Meteor.user().services.google.accessToken,
refreshToken: Meteor.user().services.google.refreshToken};
gcontacts = new GoogleContacts(opts);
gcontacts.refreshAccessToken(opts.refreshToken, function (err, accessToken)
{
if(err)
{
console.log ('gcontact.refreshToken, ', err);
return false;
}
else
{
console.log ('gcontact.access token success!');
gcontacts.token = accessToken;
gcontacts.getContacts(function(err, contact)
{
\\here i am able to access all contacts
console.log(contact);
})
}
});
为此,您需要一个来自 google 的 refreshToken
,默认情况下 meteor 不会为您获取它。
在客户端添加如下代码获取refreshtoken
(requestOfflineToken)
Accounts.ui.config({
requestPermissions: {
facebook: ['email', 'user_friends','read_friendlists'],
google:['https://www.google.com/m8/feeds']
},
requestOfflineToken: {
google: true
},
passwordSignupFields: 'USERNAME_AND_EMAIL'
});
注意:要使用联系人 API,您需要在 Google 控制台中启用联系人 API。
希望它可以帮助那里的人。
关于javascript - Meteor,访问登录用户的谷歌联系人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22735826/