在rails 4应用程序google plus中使用social_share_button_tag自定义标题未显示

Posted

技术标签:

【中文标题】在rails 4应用程序google plus中使用social_share_button_tag自定义标题未显示【英文标题】:using social_share_button_tag in rails 4 application google plus customize title is not showing 【发布时间】:2017-05-16 11:04:46 【问题描述】:

我在我的 rails 4 应用程序中使用 social_share_button_tag 将新闻分享到 facebook、twitter 和 google plus 并自定义标题。代码段如下:

<%= social_share_button_tag(@abc.full_name,
url: "#@abc.page?action=xyz&record=#@abc.id",
desc: @abc.full_name,
popup: 'true',
'data-facebook-title' => "The news of #@abc.full_name",
'data-twitter-title' => "The news of #@abc.full_name",
'data-google_plus-title' => "The news of #@abc.full_name",
'data-facebook-caption' => "The news of #@abc.full_name"

) %>

对于 facebook 和 twitter,它工作正常,但对于 google plus,标题没有显示。它正在显示其他内容(可能会自动填充一些默认值)。

documentation 中明确提到:

除默认标题外,您还可以指定特殊社交网络的标题:

<%= social_share_button_tag(@post.title, 
'data-twitter-title' => 'TheTitleForTwitter') %>

现在我该怎么办?

【问题讨论】:

【参考方案1】:

Google+ share endpoint API 只接受url(URL)和hl(语言代码)。您不能设置自定义标题。要设置标题,您必须在共享页面的 html 中填充 +Snippet。

【讨论】:

以上是关于在rails 4应用程序google plus中使用social_share_button_tag自定义标题未显示的主要内容,如果未能解决你的问题,请参考以下文章

默认情况下,如何在 Rails 中使 cookie 安全(仅限 https)?

在 Rails 4 中自动加载 lib 文件

如何在 Xcode 中使元素具有百分比宽度

如何在Rails中使数据库字段为只读?

如何在 Ruby on Rails 迁移中使列唯一并为其编制索引?

如何在 ruby​​ on rails 中使每个 user_id 的列数据唯一