• 22-10-2008, 21:35:35
    #1
    Kimlik doğrulama veya yönetimden onay bekliyor.
    Hem Sınıf yazımı hemde google api'sinin kullanımı öğrenmek için yeni başlayan arkadaşlara yararlı olacağı kanısındayım.
    <?php
    /*
    Kodlama By s4l1h
    http://pehepe.blogspot.com/
    Alıntı yaparken kaynak gösterirseniz, bu sizin emeğe saygınız olduğunu gösterir.
    */
    //Class Kodları Başlıyor.................
    class blogger{
    // Türkçe Karekterleri UTF-8 Çevirmek için
    function cevir($gel){
    if($this->dil==1){ $gel=iconv("ISO-8859-9", "UTF-8", $gel); }
    return $gel;
    }
    // XML Oluşturuyoruz
    function olustur($ad,$etiket,$icerik){
    $ad=$this->cevir($ad);
    $icerik=$this->cevir($icerik);
    $xml="<entry xmlns='http://www.w3.org/2005/Atom'>
    <title type='text'>$ad</title>
    <content type='xhtml'>
    <div xmlns=\"http://www.w3.org/1999/xhtml\">".$icerik."</div>
    </content>";
    foreach($etiket as $liz0){
    $liz0=$this->cevir($liz0);
    $xml.='<category scheme="http://www.blogger.com/atom/ns#" term="'.$liz0.'" />';
    }
    $xml.="</entry>";
    return $xml;
    }
    function user($a){
    return $this->kullanici=$a;
    }
    function pass($a){
    return $this->sifre=$a;
    }
    function no($a){
    return $this->id=$a;
    }
    function dil($a){
    return $this->dil=$a;
    }
    // Giriş Yapıyoruz
    function tokenal(){
    $ch3 = curl_init();
    curl_setopt($ch3, CURLOPT_URL, 'https://www.google.com/accounts/ClientLogin');
    curl_setopt($ch3, CURLOPT_POSTFIELDS,"Email=$this->kullanici&Passwd=$this->sifre&accountType=GOOGLE&service=blogger&source=curlbaglan");
    curl_setopt($ch3, CURLOPT_POST, 1);
    curl_setopt($ch3, CURLOPT_HEADER, 0);
    curl_setopt($ch3, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch3, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch3, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
    curl_setopt($ch3, CURLOPT_RETURNTRANSFER, 1);
    $finish = curl_exec($ch3);
    $a=explode("Auth=",$finish);
    $x=trim($a[1]);
    return $this->token=$x;
    }
    function token(){
    $this->tokenal();
    return $this->token;
    }
    // Gönderiyoruz.
    function yaz($konu,$etiket,$icerik){
    $this->token();
    $xml=$this->olustur($konu,$etiket,$icerik);
    $s=strlen($xml);
    $header[]="Content-Type: application/atom+xml";
    $header[]="Content-length: $s";
    $header[]="Authorization: GoogleLogin auth=$this->token";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'http://www.blogger.com/feeds/'.$this->id.'/posts/default');
    curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $sonuc = curl_exec($ch);
    if(strpos($sonuc,"Error") OR strpos($sonuc,"The element")){
    return "Hata OLUŞTU<br/>".$sonuc;
    }else{
    return 'Gönderme Başarılı\r\n';
    //echo $sonuc;
    }
    }
    }
    //Class Kodları Bitiyor.................
    /*
    Örnek Bir Kullanım Aşşağıdaki Gibidir.
    Öncelikle kullanıcı adı,şifre ve blogid yazalım
    blogger.com girip hesabınızdan blogidi alabilirsiniz.
    */
    $kullanici = "xxxxxxxxx@gmail.com"; // Mail adresiniz
    $sifre = "xxx"; // Şifreniz
    $id = "6492861835614290907"; // Blog id
    $konu="Blogger Post Denemesi"; // Yazı Başlığı
    /*
    Etiketler array olmalıdır aşağıdaki gibi
    */
    $etiket[]="php";
    $etiket[]="blogger";
    $etiket[]="pehepe";
    $etiket[]="s4l1h";
    /*
    Yazının içeriği
    */
    $icerik="Blogger Poster Denemesi<br/>http://pehepe.blogspot.com/<br/>";
    /*
    Blogger'e post etmek için
    */
    $blog=& new blogger; // Class'ı kullanmaya başlıyoruz
    $blog->user($kullanici); // Kullanacı adı
    $blog->pass($sifre); //Şifre
    $blog->no($id); // Blog No
    $blog->dil(1); //Yolladığımız Türkçe veriyi UTF-8'e çevirmesini istiyoruz.
    echo $blog->yaz($konu,$etiket,$icerik); // Son olarak Gönderiyoruz
    ?>
    Uygulamayı buradan indirebilirsiniz.
    Kaynak: s4l1h Kişisel Günce: Google Api & Blogger poster class
  • 23-10-2008, 19:25:59
    #2
    İlerki zamanda çok çok işime yarayacak bir kod.
    Ellerine sağlık.
    +Rep