socialworth
一个简单的PHP库,用于通过查询社交网络API来确定给定URL的普及。
它目前支持:
- Twitter(计数提及和转发)
- Facebook(计数,评论和分享)
- Google+(+ 1s)
- Pinterest(分享)
- reddit(计数提交的故事和投票)
- Stumbleupon的观点
- LinkedIn股票
-
黑客新闻API服务目前处于离线状态。 -
Mozscape反向链接退休。
该库有各种用例;生成博客最受欢迎的文章列表,以优化位置,或在您的页面上包含社交网络计数器,而不依赖于肿的外部JavaScript。
安装
要添加此软件包作为您项目的依赖性,只需将evansims/ socialworth添加到您的项目的Composer.json文件中即可。这是最小曲子的示例。JSON文件:
socialworth\”: \”*\”
}
}\”>
{
\"require\": {
\"evansims/ socialworth \": \"*\"
}
}
然后运行composer install以安装库。作曲家生成一个vendor/autoload.php文件,在调用socialworth之前,您需要在项目中包含该文件:
require \'vendor/autoload.php\';
用法
查询所有支持的服务中的所有服务:
socialworth;
$ socialworth = new socialworth (\’https://*git*hub.*com/\’);
var_dump($ socialworth ->all());
?>\”>
<?php
use Evansims\\ socialworth ;
$ socialworth = new socialworth (\'https://*git*hub.*com/\');
var_dump($ socialworth ->all());
?>
另外,您只需查询一项服务:
socialworth;
var_dump( socialworth ::twitter(\’https://g*ith*ub*.com/\’));
?>\”>
<?php
use Evansims\\ socialworth ;
var_dump( socialworth ::twitter(\'https://g*ith*ub*.com/\'));
?>
或从您的查询中忽略特定服务:
socialworth;
$ socialworth = new socialworth (\’https://*git*hub.*com/\’);
$ socialworth ->linkedin = false;
var_dump($ socialworth ->all());
?>\”>
<?php
use Evansims\\ socialworth ;
$ socialworth = new socialworth (\'https://*git*hub.*com/\');
$ socialworth ->linkedin = false;
var_dump($ socialworth ->all());
?>
all()方法将返回一个可以用来获取单个服务结果的对象,或从服务中找到合并的受欢迎程度:
socialworth;
$ socialworth = new socialworth (\’https://*git*hub.*com/\’);
$response = $ socialworth ->all();
var_dump($response->total); // Total likes, shares, upvotes, etc.
var_dump($response->reddit); // Just shares and upvotes from reddit.
var_dump($response->twitter); // Just mentions, retweets and shares on Twitter.
?>\”>
<?php
use Evansims\\ socialworth ;
$ socialworth = new socialworth (\'https://*git*hub.*com/\');
$response = $ socialworth ->all();
var_dump($response->total); // Total likes, shares, upvotes, etc.
var_dump($response->reddit); // Just shares and upvotes from reddit.
var_dump($response->twitter); // Just mentions, retweets and shares on Twitter.
?>
演示脚本
提供了一个演示脚本,可让您从浏览器或命令行查询库。
从命令行调用脚本…
$ php demo.php https://githu*b.c*om*/
或者,查询单个服务…
$ php demo.php --twitter --facebook https://githu*b.c*om*/
如果可以从您的Web服务器访问演示脚本,则可以传递URL …
http://localhost/path/to/demo.php?url=https://githu*b.c*om*/
无论是从CLI还是浏览器中,您都会收回JSON对象。
{
\"total\": 48217,
\"twitter\": 26582,
\"facebook\": 15284,
\"pinterest\": 157,
\"reddit\": 5,
\"googleplus\": 6049,
\"stumbleupon\": 297,
\"linkedin\": 0
}
这项工作的灵感来自乔纳森·摩尔(Jonathan Moore)的要旨:https://gist.github.com/2640302
