最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

运维笔记admin16浏览0评论

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

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

我正试图找到解决谷歌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的人员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/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;
  }
});
发布评论

评论列表(0)

  1. 暂无评论