我试图找到适合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)
对象。
我正在尝试为用户的联系人获取个人资料照片。如何为每个联系人加载公开个人资料图片或占位符?
答案 0 :(得分:1)
是的,可以使用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.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;
}
});