Friendfeed Api Kullanarak Uygulama Geliştirmek .
Friendfeed tartışması çok fazla sansasyona sebep oldu sanırım artık buna bir son vermek gerekir düşüncesiyle basit bir şekilde friendfeed api yazmak nasıl oluyor açıklamaya çalışacağım . Sistem için çeşitli class ' lar olmasına karşın biz curl kullanarak sisteme ulaşacağız . Ve sonrasında istediğim türde işlemleri yapmaya çalışacağız . İlk önce öğrenmeniz gereken en önemli şey http://www.friendfeed.com/remotekey adresinden öğreneceğiniz uzak anahtarınız . Eğer adresi öğrendik şimdi api yazmak istiyoruz diyorsanız buyrun başlıyoruz .
ilk önce localhostunuza veyahut internet sitenizin içerisine bir klasör açmanız gerekiyor örneğin : ff klasörünü açtınız . Aynı klasörün içerisine bir mycurl.php dosyası oluşturuyoruz ve içerisine aşağıda verdiğim kodları yazıyorsunuz.
mycurl.php kodları :
-
<?
-
-
class MyCurl
-
{
-
public $getHeaders = true; // Header için çıktı verilsin mi ?
-
public $getContent = true;
-
public $followRedirects = true; // Sayfa yönlendirmesi gerekiyorsa yönlendirme gerçekleşsin mi ?
-
-
private $fCookieFile;
-
private $fSocket;
-
-
function MyCurl()
-
{
-
$this->auth_nickname = $auth_nickname;
-
$this->auth_key = $auth_key; // işte uzak anahtar ile ilgili kısım .
-
}
-
-
function init()
-
{
-
return $this->fSocket = curl_init();
-
}
-
-
-
-
function setopt($opt, $value)
-
{
-
return curl_setopt($this->fSocket, $opt, $value);
-
}
-
-
function load_defaults()
-
{
-
$this->setopt(CURLOPT_RETURNTRANSFER, 1);
-
$this->setopt(CURLOPT_FOLLOWLOCATION, $this->followRedirects);
-
$this->setopt(CURLOPT_REFERER, "http://google.com");
-
$this->setopt(CURLOPT_VERBOSE, false);
-
$this->setopt(CURLOPT_SSL_VERIFYPEER, false);
-
$this->setopt(CURLOPT_SSL_VERIFYHOST, false);
-
$this->setopt(CURLOPT_HEADER, $this->getHeaders);
-
$this->setopt(CURLOPT_NOBODY, !$this->getContent);
-
$this->setopt(CURLOPT_COOKIEJAR, $this->fCookieFile);
-
$this->setopt(CURLOPT_COOKIEFILE, $this->fCookieFile);
-
$this->setopt(CURLOPT_USERAGENT, "MyCurl");
-
if ($this->auth_nickname && $this->auth_key) {
-
$this->setopt ( CURLOPT_USERPWD, $this->auth_nickname . ":" . $this->auth_key);
-
$this->setopt (CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
-
}
-
$this->setopt(CURLOPT_POST, 1);
-
$this->setopt(CURLOPT_CUSTOMREQUEST,'POST');
-
if($fp)
-
$this->setopt(CURLOPT_STDERR, $fp);
-
}
-
-
-
function destroy()
-
{
-
return curl_close($this->fSocket);
-
}
-
-
function head($url)
-
{
-
$this->init();
-
if($this->fSocket)
-
{
-
$this->getHeaders = true;
-
$this->getContent = false;
-
$this->load_defaults();
-
$this->setopt(CURLOPT_POST, 0);
-
$this->setopt(CURLOPT_CUSTOMREQUEST,'HEAD');
-
$this->setopt(CURLOPT_URL, $url);
-
$result = curl_exec($this->fSocket);
-
$this->destroy();
-
return $result;
-
}
-
return 0;
-
}
-
-
function get($url)
-
{
-
$this->init();
-
if($this->fSocket)
-
{
-
$this->load_defaults();
-
$this->setopt(CURLOPT_POST, 0);
-
$this->setopt(CURLOPT_CUSTOMREQUEST,'GET');
-
$this->setopt(CURLOPT_URL, $url);
-
$result = curl_exec($this->fSocket);
-
$this->destroy();
-
return $result;
-
}
-
return 0;
-
}
-
-
{
-
$this->init();
-
if($this->fSocket)
-
{
-
$post_data = $this->compile_post_data($post_data);
-
$this->load_defaults();
-
$this->setopt(CURLOPT_POSTFIELDS, $post_data);
-
-
$this->setopt(CURLOPT_HTTPHEADER, $arr_headers);
-
-
$this->setopt(CURLOPT_URL, $url);
-
-
$result = curl_exec($this->fSocket);
-
$http_code = curl_getinfo($this->fSocket, CURLINFO_HTTP_CODE);
-
$this->destroy();
-
return $result;
-
}
-
return 0;
-
}
-
-
function compile_post_data($post_data)
-
{
-
$o="";
-
foreach ($post_data as $k=>$v)
-
}
-
-
function get_parsed($result, $bef, $aft="")
-
{
-
$line=1;
-
if($pos_bef===false)
-
return "";
-
$pos_bef+=$len;
-
-
{ //try to search up to the end of line
-
if($pos_aft===false)
-
}
-
else
-
-
if($pos_aft!==false)
-
else
-
-
return $rez;
-
}
-
-
}
-
?>
Evet işte şimdi mycurl.php dosyasını yazdık şimdide index.php dosyası oluşturuyoruz . Bu sayfadan kişiler hazırladığınız api'ye giriş yapacak ve kullanmaya başlayacak .
index.php kodları :
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-
<html xmlns="http://www.w3.org/1999/xhtml">
-
<head>
-
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
-
<title>FriendFeed Api Giriş - byumut.com</title>
-
<STYLE TYPE="text/css">
-
a{
-
text-decoration:none;
-
font-size:12px;
-
font-family:"Trebuchet Ms";
-
}
-
</STYLE>
-
</head>
-
<body>
-
<a href="<?=$_SERVER['HTTP_REFFER']?>" style="color: #1030cc" target="_blank">Geri</a><br>
-
<?
-
-
-
include "mycurl.php";
-
-
$mc = new MyCurl();
-
$mc->getHeaders = false;
-
$mc->getContent = true;
-
$mc->auth_nickname = $_REQUEST['friendfeed_nickname'];
-
$mc->auth_key = $_REQUEST['friendfeed_remote_key'];
-
-
$url = "http://friendfeed-api.com/v2/feedinfo/".$mc->auth_nickname."?format=json";
-
$response = $mc->get($url);
-
$ciktiArray = json_decode($response);
-
$servisler = $ciktiArray->services;
-
-
$aboneOlduklarim = $ciktiArray->subscriptions;
-
for($i=0;$i<$abonelikSay;$i++){
-
-
(
-
"id"=>$aboneOlduklarim[$i]->id,
-
"type"=>$aboneOlduklarim[$i]->type,
-
);
-
-
}
-
$aboneOlanlar = $ciktiArray->subscribers;
-
for($i=0;$i<$abonelikSay;$i++){
-
-
-
//bak şöylede olur...
-
-
(
-
"id"=>$aboneOlanlar[$i]->id,
-
"type"=>$aboneOlanlar[$i]->type,
-
);
-
-
-
-
}
-
-
-
-
$usr_arr1 = array_keys($abone_Olanlar); //usernameleri alır, yani keyleri.. //bu array sadece username tutuyor..
-
-
-
echo "<b>Benim abone olduklarım ama bana abone olmayanlar : </b><br> ";
-
foreach($result2 as $diff_usr)
-
{
-
-
-
}
-
-
-
echo "<hr>";
-
echo "<b>Bana Abone Olan ama benim olmadıklarım : </b><br> ";
-
foreach($result as $diff_usr)
-
{
-
-
-
}
-
-
-
echo "<hr>";
-
-
echo "<b>Bana Abone Olanlar : </b><br> ";
-
foreach($abone_Olanlar as $username=>$val)
-
{
-
echo "($id,$username,$type)<br>";
-
-
}
-
-
echo "<hr>";
-
echo "<b>Benim Abone Olduklarım : </b><br> ";
-
-
foreach($abone_Olduklarim as $key=>$val)
-
{
-
echo "($id,$username,$type)<br>";
-
-
}
-
-
if(!$_POST){
-
-
?>
-
<form action="" method="post">
-
<table style="border-collapse: collapse; border-spacing: 0; padding: 0; margin: 0; font-family: Arial, sans-serif; border: 4px solid #6797d3; color: #222222">
-
<tr>
-
<td style="background-color: #ecf2fa; padding: 3px; padding-left: 5px; padding-top: 5px; border: 0; border-bottom: 1px solid #6797d3"><a href="http://friendfeed.com/" target="_blank"><img src="http://friendfeed.com/static/images/logo-api.png" width="160" height="34" alt="FriendFeed" style="padding:0; border:0; margin:0"/></a></td>
-
<td style="background-color: #ecf2fa; padding: 3px; padding-right: 20px; border: 0; border-bottom: 1px solid #6797d3; text-align: right; vertical-align: middle; font-size: 16pt; font-weight: bold; color: gray">Api Girişi</td>
-
</tr>
-
<tr>
-
<td style="background-color: white; padding: 15px; border: 0" colspan="2">
-
<table style="border-collapse: collapse; border-spacing: 0; border: 0; padding: 0; margin: 0">
-
<tr>
-
<td style="border: 0; padding: 5px; font-size: 10pt">FriendFeed Kullanıcı Adınız:</td>
-
<td style="border: 0; padding: 5px; font-size: 10pt"><input type="text" name="friendfeed_nickname" style="width: 10em"/></td>
-
</tr>
-
<tr>
-
<td style="border: 0; padding: 5px; font-size: 10pt">Uzak Anahtarınız [ <a href="http://friendfeed.com/remotekey" style="color: #1030cc" target="_blank">bilmiyorsanız</a> ]:</td>
-
<td style="border: 0; padding: 5px; font-size: 10pt"><input type="password" name="friendfeed_remote_key" style="width: 10em"/></td>
-
</tr>
-
<tr>
-
<td style="border: 0; padding: 0; padding-right: 5px; padding-top: 8px; text-align: right" colspan="2"><input type="submit" value="Giriş Yap" style="font-weight: bold; color: #222222; font-family: Arial, sans-serif; font-size: 10pt"/></td>
-
</tr>
-
</table>
-
</td>
-
</tr>
-
</table>
-
</form>
-
<?
-
}
-
?>
-
</body>
-
</html>
Gibi gerisini geliştirmek size kalmış arkadaşlar uykum geldi ondan daha fazla örnek ekleyemiyorum
kolay gelsin .
38 views