嘿伙计们,实际上我有两个问题。
1.Im tying to get user info here is a list of what information I want (using facebook API): user_likes, friends_about_me, user_birthday, email, user_location, user_work_history, read_friendlists, friends_groups, user_groups
这是我的代码:
Template.user_loggedout.events({
"click #fb":function(e,tmp){
Meteor.loginWithFacebook({
requestPermissions :
['user_likes',
'friends_about_me',
'user_birthday',
'email',
'user_location',
'user_work_history',
'read_friendlists',
'friends_groups',
'user_groups']
},function (err){
if(err){
console.log("error when login with facebook " + err);
} else {
console.log("login with facebook succeeded");
}
});
},
})
但我最终创建了一个仅包含一些字段的用户对象(来自 mongoDB 的用户 JSON 对象,我在某些字段中插入“xxx”只是为了安全):
{
"createdAt" : 1378842117154,
"_id" : "mW7urf5yZPCm6HhNK",
"services" : {
"facebook" : {
"accessToken" : "xxxx",
"expiresAt" : 1383945305007,
"id" : "xxxxxx",
"email" : "xxxx",
"name" : "Boaz",
"first_name" : "Boaz",
"last_name" : "xxx",
"link" : "https://www.facebook.com/xxxx",
"username" : "boazmier",
"gender" : "male",
"locale" : "he_IL"
},
"resume" : {
"loginTokens" : [
{
"token" : "TcLnp9GSbDasNZNCj",
"when" : 1378842117154
}
]
}
},
"profile" : {
"name" : "Boaz xxxx"
}
}
很明显,您可以看到没有 friends_list、user_birthday 等记录。
第二个问题:与 github 相同 - 我要求这个:user, public_repo, avatar_url, gist 但最终得到:
{
"createdAt" : 1378843359664,
"_id" : "pJGwTepYe2Ps7hhnS",
"services" : {
"github" : {
"id" : xxxx,
"accessToken" : "xxxxx",
"email" : "xxxxx",
"username" : "boazhoch"
},
"resume" : {
"loginTokens" : [
{
"token" : "hbNLcuC85MKwBJBfb",
"when" : 1378843359664
}
]
}
},
"profile" : {
"name" : "xxxx"
}
}
所以我最终没有头像,但是当我将服务器上的代码更改为:
Accounts.onCreateUser(function(options,user){
var accessToken = user.services.github.accessToken,result,profile;
result = Meteor.http.get("https://api.github.com/user", {
params: {
access_token: accessToken
}
});
if(result.error){
throw result.error
}
profile = _.pick(result.data,
"login",
"name",
"avatar_url",
"url",
"company",
"blog",
"location",
"email",
"bio",
"html_url");
user.profile = profile;
return user;
});
我的用户对象得到了 avatar_url 为什么会这样?我知道流星与 Account.createUser 一起发布,并通过 onCreateUser 覆盖它,但是,requestPermissions 的结果是什么?我也只能有一个 Account.onCreateUser 函数,那么如何让这个函数从每个服务请求不同的数据呢?(我想包括 facebook、google、github、twitter 和 meetup)