Meteor,Access Google contacts of loggedin user

杀马特。学长 韩版系。学妹 提交于 2019-12-11 06:59:55

问题


How to get all contacts of a loggedin user,i added request permission to access google contacts

requestPermissions: {
        facebook: ['email', 'user_friends','read_friendlists'],
         google:['https://www.google.com/m8/feeds']
    },

I don't know how to access contacts,i tried to google it but i'm confused with the results.

Does anyone know how to do this?

can anyone point me to the answer?

I really appreciate any help


回答1:


I Just used google-contacts atmosphere package and write the following function in server side and it worked for me

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);
                    })

                }
             });

To do this,you need a refreshToken from google,by default meteor will not get it for you.

Add the following code in client side to get the 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'
});

NOTE: To work with contacts API you need to enable contacts api in your google console.

Hope it may help someone out there.



来源:https://stackoverflow.com/questions/22735826/meteor-access-google-contacts-of-loggedin-user

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!