首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Services_Digg2获取URL的Digg计数?

如何使用Services_Digg2获取URL的Digg计数?
EN

Stack Overflow用户
提问于 2010-01-06 08:47:49
回答 1查看 989关注 0票数 1

目前还不清楚这个API是否能够通过URL搜索,通过G搜索,但没有太多成功。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-01-06 09:30:11

Services_Digg2只是PHP中的一个客户端库,它将所有调用转发给API,API支持通过urls进行搜索。您需要传递的是url的md5散列,而不是实际的url。PHP有一个md5函数,您可以使用它来获取url的md5散列。

然后,API调用是针对story.getAll的,并且您将先前计算的md5散列作为参数link_hash传递。

代码语言:javascript
复制
http://services.digg.com/1.0/endpoint?method=story.getAll&link_hash=a23658a0828e2fb388b7c83f61e235e6

上面的散列是针对URL的,来自http://www.nytimes.com/2010/01/05/health/05docs.html的响应是:

代码语言:javascript
复制
<stories timestamp="1262740374" total="1" offset="0" count="1"> 
 <story link="http://www.nytimes.com/2010/01/05/health/05docs.html" submit_date="1262729293" diggs="70" id="18288654" comments="6" href="http://digg.com/health/For_F_D_R_Sleuths_New_Focus_on_an_Odd_Spot" promote_date="1262739603" status="popular" media="news"> 
  <description>Look closely at Roosevelt’s portraits over his 12-year presidency. In his first two terms, there is a dark spot over his left eyebrow. It seems to grow and then mysteriously vanishes sometime around 1940, leaving a small scar.  </description> 
  <title>For F.D.R. Sleuths, New Focus on an Odd Spot</title> 
  <user name="leaprinces" registered="1227624484" profileviews="23186" fullname="Princess Leia" icon="http://digg.com/users/leaprinces/l.png" /> 
  <topic name="Health" short_name="health" /> 
  <container name="Lifestyle" short_name="lifestyle" /> 
  <thumbnail originalwidth="190" originalheight="126" contentType="image/jpeg" src="http://digg.com/health/For_F_D_R_Sleuths_New_Focus_on_an_Odd_Spot/t.jpg" width="80" height="80" /> 
  <shorturl short_url="http://digg.com/d31EjiI" view_count="192" /> 
 </story> 
</stories>

此响应中的故事元素有一个名为diggs的属性,这正是您需要的。

要通过PHP库实现这一点,代码应如下所示:

代码语言:javascript
复制
$url = "...";

$api = new Services_Digg2;
$stories = $api->story->getAll(array('link_hash' => md5($url)))->stories;

foreach($stories as $story) {
    // I am not sure how to access the diggs attribute
    // Maybe this works. If not, just
    // var_dump the $story object and 
    // see how to access the digg count information.
    echo $story['diggs'];
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2010256

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档