From del.icio.us to Google Co-op 2



1.改造
さて、先日こちらで、Google Co-opdel.icio.usのデータを移植する方法を書いてみたのですが、どうも、del.icio.usのデータをRSSでとると31データしか取得できないようなので、APIで取得する方法に変えたものを作成してみた。


2. del.icio.us xmlAPIで取得する。
APIでデータ取得する場合は、httpsを使用してhttp-authの利用が必要。
このとき、以下でデータの取得を行う。

https://del.icio.us user id:del.icio.us user password@api.del.icio.us/v1/posts/all?tag=Tagname

これを以下でデータ取得する。


info_delicious2.php
delID=$mydelID;
}

public function SetdelPass($mydelPass){
$this->delPass=$mydelPass;
}

public function SetdelTag($MydelTag){
$this->delTag=urlencode($MydelTag);
}

public function GetdelInfo(){
if($this->delTag=="" or $this->delID=="" or $this->delPass==""){
$this->delInfo["message"]="Tag,ID or Pass does not set!";
}else{
$this->url="https://".$this->delID.":".$this->delPass."@api.del.icio.us/v1/posts/all?tag=".$this->delTag;
echo $this->url."\n";
$this->GeneratedelInfo();
//print($this->url);
if($this->itemnum==0){
$this->delInfo["message"]="No Result";
}
}
return($this->delInfo);
}

private function GeneratedelInfo(){
$XMLRead=new XMLReader;
//print($this->url);
$this->itemnum=0;
if($XMLRead->open($this->url)){
while($XMLRead->read()){
switch($XMLRead->name){
Case "post":
$this->delInfo["post"][$this->itemnum]["link"]= $XMLRead->getAttribute("href");
$this->delInfo["post"][$this->itemnum]["title"]= $XMLRead->getAttribute("description");
$this->delInfo["post"][$this->itemnum]["tag"]= $XMLRead->getAttribute("tag");
$this->delInfo["post"][$this->itemnum]["time"]= $XMLRead->getAttribute("time");
break;
default:
break;
}
$this->itemnum+=1;
echo $this->itemnum."\n";
}
$XMLRead->close;
$this->delInfo["count"]=$this->itemnum;
}
}
}
?>



3. これをGoogle Co-op へ移行するXML
こちらは、ほとんど変更なしだけれど、del.icio.us側の変更に伴って、いくつかの変更を追加。
また、"*"でサイトの全てを検索対象に出来るのだけれど、どうも、これをやると検索結果が偏りすぎて使いにくそうなので、それは廃止にしました。


info_delicious2.php
SetdelTag('TagName');
$ResdelInfo->SetdelID('del.icio.us User ID');
$ResdelInfo->SetdelPass('del.icio.us user password');
$dellink=$ResdelInfo->GetdelInfo();

//Prepare Strings from Recieved data
if($dellink["message"]!="No Result"){
$XMLout ='';
$XMLout.="\n";
foreach($dellink["post"] as $value){
$value["link"]=substr($value["link"],7);
echo $value["title"]."\n";
$XMLout.=' ';
$XMLout.="\n";
$XMLout.='

$label=explode(" ",$value["tag"]);
foreach($label as $tag){
$XMLout.='

$XMLout.=' ';
$XMLout.="\n";
}
$XMLout.='';
$XMLout.="\n";
//Write to XML file
$fpwrite = fopen("googlecoop.xml", "w");
fwrite($fpwrite,$XMLout);
fclose($fpwrite);
}
?>



関連リンク:
dLINKbRING.Search.ProgressiveRock
Powered BY AmazoRogi