7

我正在用 PHP 建立一个论坛,我希望用户能够使用 Addthis 社交插件将每个帖子的标题和描述分享到 facebook、twitter 等。这是 Addthis 给我的代码:

    <!-- AddThis Button BEGIN -->
    <div class="addthis_toolbox addthis_default_style "
        addthis:url="www.example.com"
        addthis:title="Example Title"
        addthis:description="Example Description">
    <a class="addthis_button_preferred_1"></a>
    <a class="addthis_button_preferred_2"></a>
    <a class="addthis_button_preferred_3"></a>
    <a class="addthis_button_preferred_4"></a>
    <a class="addthis_button_compact"></a>
    <a class="addthis_counter addthis_bubble_style"></a>
    </div>
    <script type="text/javascript" src="http://s6.addthis.com/js/154/addthis_widget.js#pubid=rd-39e8r89e9er8er989"></script>
    <!-- AddThis Button END -->

我能够将 url 更改为我指定的另一个,但更改标题和描述没有效果。事实上,当我点击分享按钮并将其发布到我的 Facebook 墙上时,它们甚至都不会出现。什么是让它工作的正确方法?

4

4 回答 4

3

据我所知,AddThis 并没有正式支持所有这些参数(我无法在他们的文档中一次找到它们),所以理想情况下你应该只在你所在的页面上使用 OpenGraph 标记。但无论如何...

您需要在自定义按钮本身上指定它,而不是在工具箱上。您甚至可以指定图像。如果您的按钮必须来自 AddThis 而不是自己指定,我不确定。

<div class="addthis_sharing_toolbox">
    <a class="addthis_button_facebook"
        addthis:url="http://google.com/"
        addthis:title="Here's a title"   
        addthis:media="http://images.google.com/example.png" 
        addthis:description="Here's a cool description">
        <i class="ico ico-facebook"></i>
    </a>

    <a class="addthis_button_twitter"
        addthis:url="http://google.com/"
        addthis:title="Here's a title"   
        addthis:media="http://images.google.com/example.png" 
        addthis:description="Here's a cool description">
        <i class="ico ico-twitter"></i>
    </a>

    <a class="addthis_button_linkedin"
        addthis:url="http://google.com/"
        addthis:title="Here's a title"   
        addthis:media="http://images.google.com/example.png" 
        addthis:description="Here's a cool description">
        <i class="ico ico-facebook"></i>
    </a>
</div>

AddThis 的文档很烂,所以我碰巧遇到了正确的事情并弄清楚了这一点。享受!

于 2016-10-06T19:40:05.237 回答
2

AddThis具体建议您使用来自 Open Graph Protocol的元标记来指定要显示的内容

我们强烈建议使用页面标记方法,而不是将您的小部件参数传递给我们的 API

因此,在您的情况下,您应该拥有原始代码:

<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_default_style">
<a class="addthis_button_preferred_1"></a>
<a class="addthis_button_preferred_2"></a>
<a class="addthis_button_preferred_3"></a>
<a class="addthis_button_preferred_4"></a>
<a class="addthis_button_compact"></a>
<a class="addthis_counter addthis_bubble_style"></a>
</div>
<script type="text/javascript" src="http://s6.addthis.com/js/154/addthis_widget.js#pubid=rd-39e8r89e9er8er989"></script>
<!-- AddThis Button END -->

并在您的示例中更改标题以包含 addThismeta标记,例如:

<meta property="og:url" content="http://www.example.com" />
<meta property="og:title" content="Example Title" />
<meta property="og:description" content="Example Title Description" />
<meta property="og:image" content="http://www.example.com/logo.gif" />

这避免了您在客户端 API 中可能遇到的任何问题。

于 2011-08-21T08:17:46.687 回答
2

I went around and around before finding this on the AddThis website:

Setting the URL & Title to Share

...for our newest tools, use the data-url and data-title parameters...

I am using their latest code (addthis_sharing_toolbox instead of addthis_toolbox) and all I could find were people using addthis:url="" which was not working.

于 2014-07-19T21:32:06.897 回答
0

为避免由于图像引起的任何错误,请尝试将图像宽度设置为最小

<meta property="og:image" content="@TempData["image"]" />
<meta property="og:title" content="@TempData["title"]" />
<meta property="og:url" content="@TempData["url"]" />
<meta property="og:image:width" content="400" />
<meta property="og:image:height" content="400" />
<meta property="og:description" content="@TempData["description"]" />
<meta name="twitter:title" content="@TempData["title"]">
<meta name="twitter:description" content="@TempData["description"]">
<meta name="twitter:image" content="@TempData["image"]">
<meta name="twitter:card" content="summary_large_image">
<meta charset="utf-8" />

在需要内联工具箱的页面中添加

  <div class="addthis_inline_share_toolbox"></div>

在关闭正文标记之前在布局/母版页面中添加了 widget.js

<script type="text/javascript" src="https://s7.addthis.com/js/300/addthis_widget.js#pubid=yourpubID"></script>
</body> 

*****如果以下检查信息有任何错误会有所帮助****

于 2021-09-15T09:31:33.657 回答