【问题标题】:get avatar omniauth discord Ruby on Rails获取头像omniauth discord Ruby on Rails
【发布时间】:2021-04-17 12:22:16
【问题描述】:

在我的 user.rb 中,我尝试保存指向头像的链接:

def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
user.provider = auth.provider
user.uid = auth.uid
user.email = auth.info.email
user.password = Devise.friendly_token[0,20]
user.image = auth.info.image
end

它适用于omniauth-google-oauth2,但不和谐我只得到图像src的一半。例如:

https://cdn.discordapp.com/avatars/714396517990037405/

其中 /714396517990037405/ 是用户 ID,缺少图像名称

【问题讨论】:

    标签: ruby omniauth


    【解决方案1】:

    这似乎是omniauth-discord gem 的一个错误。他们concatenate the URL without checking whether an avatar is actually set。

    但如果你查看Discord documentation,avatar 实际上是?string 类型,所以它可以是null。

    一般建议:如果某些东西不起作用并且它是开源的,请查看幕后。您可能不仅会很快找到解释或解决方案,而且还会了解您在此过程中使用的东西。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-14
      • 2013-05-30
      • 1970-01-01
      • 2012-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多