Sas*_*nth 1 javascript meteor meteorite
如何获取已登录用户的所有联系人,我添加了访问谷歌联系人的请求权限
requestPermissions: {
facebook: ['email', 'user_friends','read_friendlists'],
google:['https://www.google.com/m8/feeds']
},
Run Code Online (Sandbox Code Playgroud)
我不知道如何访问联系人,我试图谷歌它,但我对结果感到困惑.
有谁知道如何做到这一点?
任何人都能指出我的答案吗?
我非常感谢任何帮助
我刚刚使用了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);
})
}
});
Run Code Online (Sandbox Code Playgroud)
要做到这一点,你需要一个refreshToken谷歌,默认情况下流星将不会为你得到它.
在客户端添加以下代码以获取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'
});
Run Code Online (Sandbox Code Playgroud)
注意:要使用联系人API,您需要在Google控制台中启用联系人API.
希望它可以帮助那里的人.