流星无法访问个人资料图片

时间:2014-11-09 01:07:20

标签: facebook node.js login meteor webstorm

我是meteor的新手,我正在尝试获取当前登录用户的图片。

我尝试了很多方法,但这个方法感觉应该可行:

这是在索引的js:

Template.user_loggedout.events({
"click #login" : function(e, t){
    Meteor.loginWithFacebook({
    })
   }
})

所以它基本上只是用facebook登录。到目前为止,身份验证是成功的。 现在在服务器端,我尝试了许多方法来创建用户时获取图片,但这个方法似乎是最干净和最简单的:

Accounts.onCreateUser(function(options, user) {
if (options.profile) {
    options.profile.picture = "http://graph.facebook.com/" + user.services.facebook.id + "/picture/?type=large";
    user.profile = options.profile;
}
return user;
});

我也尝试使用谷歌(完全实施谷歌登录):

user.profile.profile_picture = user.services.google.picture;

现在在我看来,我只是这样说:

<img src="currentUser.profile.picture"

事情是无论我尝试哪种方式,我都会得到这个破碎的链接图像:

enter image description here

我确信我是一个显而易见的步骤,但我真的无法弄清楚我的电话有什么问题。我做错了吗?

2 个答案:

答案 0 :(得分:2)

您应该将助手包含在双花括号{{helper}}中。否则它会将其视为纯文本。

<img scr="{{currentUser.profile.picture}}" alt="{{currentUser.username}}">

答案 1 :(得分:2)

删除最终出现的if(options.profile)

Accounts.onCreateUser(function(options, user) {
  options.profile.picture = "http://graph.facebook.com/" + user.services.facebook.id + "/picture/?type=large";
  user.profile = options.profile;
  return user;
});

然后在你的模板中

{{#if currentUser}}
  <img scr="{{currentUser.profile.picture}}" alt="{{currentUser.username}}">
{{/if}}
相关问题