Question

Il est pas clair si cette API est encore capable de rechercher par URL, recherche par G, sans grand succès.

Était-ce utile?

La solution

Services_Digg2 est juste une bibliothèque client en PHP qui transmet tous les appels à l'API et l'API ne supporte la recherche par urls. Ce que vous devez passer est le md5 de l'URL au lieu de l'URL. PHP a une fonction md5 que vous pouvez utiliser pour obtenir le md5 d'une URL.

L'appel API serait alors pour story.getAll et vous passez le md5 précédemment calculé comme paramètre link_hash.

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

Ce hachage ci-dessus est l'URL http: // www. nytimes.com/2010/01/05/health/05docs.html et la réponse de l'API est:

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

L'élément de l'histoire dans cette réponse a un attribut appelé diggs qui est ce que vous avez besoin.

Pour obtenir ce à travers la bibliothèque PHP, le code devrait ressembler à:

$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'];
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top