English 中文(简体)
How to get Digg count of a URL using Services_Digg2?
原标题:
  • 时间:2010-01-06 00:47:48
  •  标签:
  • php
  • pear
  • digg

It isn t clear if this API is even capable of searching by URL, searched through G, without much success.

最佳回答

Services_Digg2 is just a client library in PHP that forwards all calls to the API and the API does support searching by urls. What you need to pass is the md5 hash of the url instead of the actual url. PHP has a md5 function that you can use to get the md5 hash of a url.

The API call then would be for story.getAll and you pass the previously calculated md5 hash as a parameter link_hash.

http://services.digg.com/1.0/endpoint?method=story.getAll&link_hash=a23658a0828e2fb388b7c83f61e235e6

This hash above is for the URL http://www.nytimes.com/2010/01/05/health/05docs.html and the response from the API is:

<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>

The story element in this response has an attribute called diggs which is what you need.

To get this through the PHP library, the code should look something like:

$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 ];
}
问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签