简体   繁体   English

如何使用流星显示twitter和instagram @(用户名)作为配置文件名称?

[英]How to display twitter and instagram @ (usernames) as a profile name with meteor?

I'm trying to make a variable to choose from 2 differents values, if one is null then select the other. 我正在尝试使一个变量从2个差值中选择,如果一个为null,则选择另一个。

author: '@'+ user.services.instagram.username.toUpperCase() || user.services.twitter.screenName.toUpperCase()

This results in an error when I try to comment on a Twitter account. 当我尝试在Twitter帐户上发表评论时,这会导致错误。

TypeError: Cannot read property 'instagram' of undefined

Here a snap code 这是一个短代码

comment = _.extend(commentAttributes, {
  userId: user._id,
  // author: '@'+user.services.instagram.username.toUpperCase(),
  author: '@'+ user.services.instagram.username.toUpperCase() || user.services.twitter.screenName.toUpperCase(),
  submitted: formatDate(new Date())
});
  1. Your error message simply says that your user.services variable is undefined . 您的错误消息只是说您的user.services变量是undefined
  2. '@' + null gives '@null' , so it is always truthy. '@' + null给出'@null' ,所以它总是真实的。

I found the solution. 我找到了解决方案。 I was trying to pull @ handles of instagram and twitter with the 'same' variable, so I can use it as a profile name. 我试图使用'same'变量拉动instagram和twitter的@句柄,因此可以将其用作配置文件名称。 The problem was Instagram is using services.instagram.username and Twitter is using services.twitter.screenName 问题是Instagram正在使用services.instagram.username,而Twitter正在使用services.twitter.screenName

I could fix this editing the meteor packages but that is not a complete solution, instead I made a condition for 'Account.onCreateUser' based on this . 我可以解决编辑流星包的问题,​​但这不是一个完整的解决方案,而是基于this为'Account.onCreateUser'创建了条件。

So I just made that profile.name is saving user @ instead of name. 所以我只是使profile.name保存用户@而不是name。

        if (service == 'instagram') {
            if (!user.profile)
                user.profile = {};
            if (!user.profile.name)
                user.profile.name = user.services[service].username;
        }

        if (service == 'twitter') {
          if (!user.profile)
                user.profile = {};
          if (!user.profile.name)
                user.profile.name = user.services[service].screenName;
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM