我正在尝试获取经过身份验证的Facebook用户的个人资料图片,以便在Meteor应用程序中使用.我尝试了以下内容
Meteor.publish("facebook_avatar_url", function() {
return Meteor.users.find({_id: this.userId}, {fields: {
'services.facebook.id': 1,
'services.facebook.name': 1,
'services.facebook.gender': 1,
'services.facebook.picture': 1,
'services.facebook.picture.data': 1,
'services.facebook.picture.data.url': 1
}});
});
Run Code Online (Sandbox Code Playgroud)
它只返回id,name和gender.这似乎是我想要的,以及推荐的解决方案.唯一的问题是没有关于用户图片的数据被返回.
我尝试将以下内容添加到server/server.js,根据其他帖子的建议,但它a)似乎不是推荐的方法,而b)似乎没有做任何事情.所以,它似乎是一个死胡同,但有人似乎认为它可以用于获取配置文件图片加载.
var getFbPicture;
Accounts.loginServiceConfiguration.remove({
service: "facebook"
});
Accounts.onCreateUser(function(options, user) {
if (options.profile) {
options.profile.picture = getFbPicture(user.services.facebook.accessToken);
user.profile = options.profile;
}
return user;
});
getFbPicture = function(accessToken) {
var result;
result = Meteor.http.get("https://graph.facebook.com/me", {
params: {
access_token: accessToken,
fields: 'picture'
}
});
if (result.error) {
throw result.error;
}
return result.data.picture.data.url;
};
Run Code Online (Sandbox Code Playgroud)
所以,我有点不确定在这一点上要走哪条路.这是否需要在Facebook Graph API上设置权限?或者在Facebook应用程序上?我是否在发布功能中出现了错误的语法?我是否需要重新访问onCreateUser函数?
我正在寻找一个Meteor.loginWithGoogle的实例(与流星0.6.4.1).
我发现这个用于loginWithGitHub(https://www.eventedmind.com/posts/meteor-customizing-login),可以正常使用GitHub.
没有参数,它工作正常,如客户端显示:
Template.user_loggedout.events({
"click #login": function(e, tmpl){
Meteor.loginWithGoogle({
}, function (err) {
if(err) {
//error handling
alert('error : '+err.message);
} else {
}
});
}
});
Run Code Online (Sandbox Code Playgroud)
与服务器端的帐户参数:
Accounts.loginServiceConfiguration.remove({
service: 'google'
});
Accounts.loginServiceConfiguration.insert({
service: 'google',
clientId: 'XXXXXX',
secret: 'YYYYYY'
});
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我如何获得currentUser信息,尤其是邮件?有没有办法获取用户的Google+个人资料(如果他有一个并允许这个),例如用户的头像?requestPermissions需要的参数是什么:,我可以得到什么?
谢谢
我正在使用Meteor进行一个项目.人们可以使用Twitter登录.我想知道是否有办法在Accounts.onCreateUser中从Twitter获取某人个人资料图片.这就是我的意思:
Accounts.onCreateUser(function(options, user) {
var twitterInfo = user.services.twitter;
if (options.profile){
options.profile.createdAt = new Date();//now!
options.profile.twitterId = twitterInfo.id;
options.profile.username = twitterInfo.screenName;
options.profile.name = options.profile.name;
user.profile = options.profile;
}
return user;
});
Run Code Online (Sandbox Code Playgroud)
谢谢!