javascript - Meteor,访问登录用户的谷歌联系人

标签 javascript meteor meteorite

如何获取登录用户的所有联系人,我添加了访问谷歌联系人的请求权限

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/

相关文章:

javascript - 如何在 Meteor 中的多个模板之间切换?

JavaScript 无法找到某些 html 元素

javascript - 不能迭代 while 语句

java - 查找周围给定经纬度的纬度值(即: location) with specified radius using java program

javascript - 从 Meteor 模板注入(inject) Javascript

meteor - 如何使用铁路由器提供静态内容(图像、字体等)

javascript - 语义 UI Vue JS 更改不起作用或未触发

javascript - meteor DOMException : Unable to decode audio data

javascript - 发现 meteor ,第 3-5 章 : plain grey screen and no data

Meteor 陨石 npm 版本锁