services_digg2를 사용하여 URL의 digg count를 얻는 방법?
문제
이 API가 G를 통해 검색 한 URL에서 검색 할 수 있는지 여부는 확실하지 않습니다.
해결책
Services_DIGG2는 PHP의 클라이언트 라이브러리 일 뿐이며 모든 호출을 API로 전달하고 API는 URL의 검색을 지원합니다. 전달해야 할 것은 실제 URL 대신 URL의 MD5 해시입니다. PHP에는 a가 있습니다 MD5 URL의 MD5 해시를 얻는 데 사용할 수있는 기능.
API 호출은 story.getAll
그리고 이전에 계산 된 MD5 해시를 매개 변수로 전달합니다. link_hash
.
http://services.digg.com/1.0/endpoint?method=story.getAll&link_hash=a23658a0828e2fb388b7c83f61e235e6
위의 해시는 URL 용입니다 http://www.nytimes.com/2010/01/05/health/05docs.html API의 응답은 다음과 같습니다.
<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 라이브러리를 통해이를 얻으려면 코드는 다음과 같습니다.
$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'];
}
제휴하지 않습니다 StackOverflow