以编程方式获取 LinkedIn 共享页面统计信息

发布于 2024-12-15 09:11:11 字数 1010 浏览 1 评论 0原文

我正在寻找一种方法来获取页面的 linkedin 共享按钮统计信息。 例如,我正在编写一个 PHP 类,当您在网站上使用我的类时,如下所示:

include("shareButtonStats.class.php");
$stats = new shareButtonStats;
echo "This page shared " . $stats->show . " times on LinkedIn";

如您所见,我需要获取该页面的共享次数统计信息。

如您所知,当我们为共享按钮添加 L??nkedIn 的 js 文件时(从这里),它包括我们页面的一些 HTML 代码。像这样的事情:

<span class="IN-widget" style="line-height: 1; vertical-align: baseline; display: inline-block; text-align: center;">
<span style="padding: 0pt ! important; margin: 0pt ! important; text-indent: 0pt ! important; display: inline-block ! important; vertical-align: baseline ! important; font-size: 1px ! important;">
<span id="li_ui_li_gen_1321370527058_1-container" class="IN-top">
<span id="li_ui_li_gen_1321370527058_1" class="IN-top">   
 .......

如果我得到该 HTML 代码,而不将其直接包含到页面中,我可以在其上使用正则表达式,然后获取共享按钮计数:)

你对我有什么想法吗?

I'm looking for a way to getting linkedin share button stats of a page.
For example, I'm writing a PHP class, when you use my class on your website like this:

include("shareButtonStats.class.php");
$stats = new shareButtonStats;
echo "This page shared " . $stats->show . " times on LinkedIn";

As you can see I need to get that page's stats for how many times shared .

As you know when we add LİnkedIn's js file for Share Button (from here), it's including some HTML codes to our page. Something like this :

<span class="IN-widget" style="line-height: 1; vertical-align: baseline; display: inline-block; text-align: center;">
<span style="padding: 0pt ! important; margin: 0pt ! important; text-indent: 0pt ! important; display: inline-block ! important; vertical-align: baseline ! important; font-size: 1px ! important;">
<span id="li_ui_li_gen_1321370527058_1-container" class="IN-top">
<span id="li_ui_li_gen_1321370527058_1" class="IN-top">   
 .......

If I get that HTML codes, without including it to page directly, I can use a RegEx over it, and then get share button count :)

Have you got any idea for me?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

薄情伤 2024-12-22 09:11:11

我相信他们会这样做,而且它是一个需要 URL 的简单网页。它返回 JavaScript 或 PHP 可以解析的 JSON

,希望这有帮助

http://www.linkedin.com/countserv/count/share?url=http://www.apple.com

I believe they do and its a simple web page that requires the URL. it returns JSON which either JavaScript or PHP could parse

hope this helps

http://www.linkedin.com/countserv/count/share?url=http://www.apple.com

差↓一点笑了 2024-12-22 09:11:11

LinkedIn 提供了一个外部 API 来完成此任务。以下是您可以如何使用它:

function getLinkedInCount($url)
{
    $curl = curl_init("http://www.linkedin.com/cws/share-count?url=" . $url);
    if (is_resource($curl) === true)
    {
        curl_setopt($curl, CURLOPT_FAILONERROR, true);
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_REFERER, "http://www.linkedin.com/");

        $result = false;
                $retries = 3;
        while (($result === false) && (--$retries > 0))
        {
            $result = curl_exec($curl);
        }
        curl_close($curl);
    }
    $arr = json_decode(substr($result, 26));
    return $arr->count;
}

echo getLinkedInCount("http://www.google.com/") . "\n";

我使用了 cURL,但是您可以使用另一种下载页面的方法。

有关现场演示,请参阅:http://codepad.viper-7.com/VDD5aI

LinkedIn provides an external API that does just that. Here is how you might use it:

function getLinkedInCount($url)
{
    $curl = curl_init("http://www.linkedin.com/cws/share-count?url=" . $url);
    if (is_resource($curl) === true)
    {
        curl_setopt($curl, CURLOPT_FAILONERROR, true);
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_REFERER, "http://www.linkedin.com/");

        $result = false;
                $retries = 3;
        while (($result === false) && (--$retries > 0))
        {
            $result = curl_exec($curl);
        }
        curl_close($curl);
    }
    $arr = json_decode(substr($result, 26));
    return $arr->count;
}

echo getLinkedInCount("http://www.google.com/") . "\n";

I used cURL for this, however you could use another method of downloading the page.

For a live demo, see: http://codepad.viper-7.com/VDD5aI

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文