本文介绍了答案是“如何获得Facebook分享和喜欢某些网址?”问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个网站,我需要从不同的网站检索Facebook的共享和许多链接和URL。



问题是,对于一些URL不可能得到我想要的例如,当我查找有关 http://www.example.com/?a=1&b=2&c=3 的所有链接的数据获取关于 http://www.example.com/?a=1 和网址的其余部分的错误数据(& b = 2& ; c = 3 )被Facebook忽略。



在StackOverflow中,很多人都在寻找答案,许多问题根本没有答案。所以,一旦我做到了,我回来告诉我怎么做。



P.S。 :仅适用于非Facebook网址。如果您正在寻找股票,并喜欢内部Facebook链接(图像,视频...)的计数,这将不适用于您。我将使用PHP来回答这个问题。

解决方案

为了获得喜欢和股票数量,我使用FQL而不是Graph API(即使我实际上使用Graph API发送查询)。



但这还不够:为了能够这样做,我已经调用了 rawurlencode()函数我想要获取数据的URL。否则,我会不断收到错误。



所以,这个喜欢(),我使用的功能有:

 函数喜欢($ url){
$ url = rawurlencode($ url);
$ json_string = file_get_contents(http://graph.facebook.com/fql?format=json&q=SELECT%20share_count,%20like_count%20FROM%20link_stat%20WHERE%20url='$url);
$ json = json_decode($ json_string,true);
if(key_exists(data,$ json)){
if(is_array($ json [data])){
if(array_key_exists(0,$ json [ data])){
return intval($ json [data] [0] [share_count])+ intval($ json [data] [0] [like_count ]);
} else {
echo错误:'0'不是键< br />;
return 0;
}
} else {
echo错误:data is no table< br />;
return 0;
}
} else {
echo错误:无数据键< br />;
return 0;
}
}

我希望这有助于有人一天: p>

I am building a website where I need to retrieve Facebook shares and likes of numerous links and URLs from different sites.

The problem is, for some URLs it is impossible to get what I wanted. For example, when I look for data about links that look like http://www.example.com/?a=1&b=2&c=3 all I get is wrong data about http://www.example.com/?a=1 and the rest of the URL (&b=2&c=3) is simply ignored by Facebook.

Here at StackOverflow, a lot of people are looking for an answer and many questions are simply unanswered. So, once I did it right, I'm back to tell how I did it.

P.S. : This works only for non-Facebook URLs. If you're looking for shares and likes counts of an internal Facebook link (image, video ...), this won't work for you. I'll be using PHP to answer the question.

解决方案

To get likes and shares counts, I use FQL instead of the Graph API (even though I am actually using the Graph API to send the query).

But this is not enough : to be able to do so, I had call the rawurlencode() function on the URL I want to get data about. Otherwise, I'll keep getting errors.

So, this likes(), the function I am using to have the counts :

function likes($url) {
    $url = rawurlencode($url);
    $json_string = file_get_contents("http://graph.facebook.com/fql?format=json&q=SELECT%20share_count,%20like_count%20FROM%20link_stat%20WHERE%20url='$url'");
    $json = json_decode($json_string, true);
    if (key_exists("data", $json)) {
        if (is_array($json["data"])) {
            if (array_key_exists("0", $json["data"])) {
                return intval($json["data"]["0"]["share_count"]) + intval($json["data"]["0"]["like_count"]);
            } else {
                echo "Error : '0' is no key<br/>";
                return 0;
            }
        } else {
            echo "Error : data is no table <br/>";
            return 0;
        }
    } else {
        echo "Error : No data key <br/>";
        return 0;
    }
}

I hope this will help someone someday :)

这篇关于答案是“如何获得Facebook分享和喜欢某些网址?”问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 05:33