我正在尝试绕过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)对象。
我正在尝试获取用户联系人的头像。如何加载每个联系人的公共资料图片或占位符?
发布于 2017-12-19 13:53:52
是的,使用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;
}
});https://stackoverflow.com/questions/47877982
复制相似问题