是否可以使用谷歌的人物 API 加载联系人图片?



我试图在Google的People API中找到自己的方式。到目前为止,我已经能够使用

加载联系人组
try{
    contact_groups = await new Promise(function(resolve, reject){
        people.contactGroups.list({
            auth: oauth2Client
        }, function(error, response){
            if(!error){
                resolve(response);
            }else{
                reject(error);
            }
        });
    });
}catch(error){
    throw error;
};

其中people是实例化的google-api-nodejs-client people(v1)对象。

我正在尝试获取用户联系人的个人资料图片。如何为每个联系人加载公共个人资料图片或占位符?

是的,可以使用Google的People API。

const google = require('googleapis');
const OAuth2 = google.auth.OAuth2;
var oauth2Client = new OAuth2(
  'CLIENT_ID',
  'CLIENT_SECRET'
  'http://localhost:3000/auth/google/callback'
);
router.get('/signin', function(req, res, next){
  var url = oauth2Client.generateAuthUrl({
    scope: [
      'https://www.googleapis.com/auth/contacts.readonly'
    ]
  });
  res.redirect(url);
});
router.get('/google/callback', function(req, res, next){
  oauth2Client.getToken(req.query.code, async function(err, tokens){
    if(!err){
      oauth2Client.credentials = tokens;
      try{
        var contacts = await new Promise((resolve, reject) => {
          people.people.connections.list({
            resourceName: 'people/me',
            auth: oauth2Client,
            personFields: 'names,photos'
        }, function(error, response){
          if(!error){
            resolve(response);
        }else{
          reject(error);
        }
      })
    });
  }catch(error){
    throw error;
  }
});

最新更新