2012-05-09 19 views

cevap

17

PHP kodu oluşturmak için php mysql kullanabilirsiniz. Bunu şablonunuza yerleştirmeniz gerekiyor. Bu komut dosyasını dışarı çalışmak için yapması gereken

<ul> 
<?php 
//function to retrieve posts from facebook’s server 
function loadFB($fbID){ 
    $url = "http://graph.facebook.com/".$fbID."/feed?limit=3"; 
    // Update by MC Vooges 11jun 2014: Access token is now required: 
    $url.= '&access_token=YOUR_TOKEN|YOUR_ACCESS_SECRET';// * 

    //load and setup CURL 
    $c = curl_init($url); 
    curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); 
    //get data from facebook and decode JSON 
    $page = json_decode(curl_exec($c)); 
    //close the connection 
    curl_close($c); 
    //return the data as an object 
    return $page->data; 
} 

/* Change These Values */ 
// Your Facebook ID 
$fbid = "190506416472588"; 
// How many posts to show? 
$fbLimit = 10; 
// Your Timezone 
date_default_timezone_set("America/Chicago"); 


/* Dont Change */ 
// Variable used to count how many we’ve loaded 
$fbCount = 0; 
// Call the function and get the posts from facebook 
$myPosts = loadFB($fbid); 


//loop through all the posts we got from facebook 
foreach($myPosts as $dPost){ 
    //only show posts that are posted by the page admin 
    if($dPost->from->id==$fbid){ 
     //get the post date/time and convert to unix time 
     $dTime = strtotime($dPost->created_time); 
     //format the date/time into something human readable 
     //if you want it formatted differently look up the php date function 
     $myTime=date("M d Y h:ia",$dTime); 
     ?> 
     <ul> 
      <li><?php echo($dPost->message) . $myTime; ?></li> 
     </ul> 
     <?php 
     //increment counter 
     $fbCount++; 
     //if we’ve outputted the number set above in fblimit we’re done 
     if($fbCount >= $fbLimit) break; 
    } 
} 
?> 
</ul> 

İki şey.

  1. sunucu cURL Sizinkiyle senaryodan Facebook kimliğinin değiştirilmesi gerekecektir
  2. etkin olduğundan emin olun.

Erişim, belirteç bu şekilde alabilirsiniz *:

$token = 'https://graph.facebook.com/oauth/access_token?client_id='.APP_ID.'&client_secret='.APP_SECRET.'&grant_type=client_credentials'; 
$token = file_get_contents($token); // returns 'accesstoken=APP_TOKEN|APP_SECRET' 
+6

Bu işe görünmektedir - 'print_r ($ sayfa);' fonksiyon loadFB 'in' return' (önceki) 'belirten bir hata döndürür Bir erişim belirteci gereklidir .. Özellikle, döner: 'stdClass Nesnesi ([error] => stdClass Nesnesi ([message] => Bu kaynağı istemek için bir erişim belirteci gereklidir. [type] => OAuthException [code] => 104)). – DACrosby

+1

Ne sonuç boş ise accesstoken – Martijn

+0

ile ilgili bir güncelleme yaptık? – user3777827

14
  1. Girişi "Apps"
  2. Kayıt Yeni uygulama, sadece ihtiyaç geliştiriciler bölümünü facebok için
  3. Git Facebook'a Yeni uygulamayı kaydetmek için, tüm ek veriler isteğe bağlıdır.
  4. Uygulama kimliğinizi/API Anahtarınızı ve Uygulama Sırrınızı bu samden kopyalayın e "Apps" bölümü.
  5. Kopya facebook.php ve sunucunuza repo den base_facebook.php dosyaları
  6. API Kullanım polymorphic query,

    require 'facebook.php'; 
    $facebook = new Facebook(array(
        'appId' => 'YOUR_APP_ID', 
        'secret' => 'YOUR_APP_SECRET', 
    )); 
    
    $fbApiGetPosts = $facebook->api('/YOUR_FACEBOOK_ACCOUNT_ID/feed?limit=5'); 
    if (isset($fbApiGetPosts["data"]) && !empty($fbApiGetPosts["data"])) { 
        // display contents of $fbApiGetPosts["data"] array 
    } 
    

    uygulama kimliğiyle YOUR_APP_ID değiştirin facebook hesabından duvar içeriği istemesini, uygulama sır ve YOUR_FACEBOOK_ACCOUNT_ID ile YOUR_APP_SECRET hedef facebook hesabı ile,

polimorfik sorgu temelde yol/URL. Daha önce sözü edilen facebook api reference docs içinde daha fazla bilgi.

Hedef facebook hesabı duvarınız herkese açıksa, bunları görüntülemek için başka bir şeye ihtiyacınız olmayacak.

+0

'u iletirken 'https: //' kullanmalısınız. http://volos-minsk.by/facebook-test-stackoverflow-app.html –

+0

Bu kontrol edilen cevap olmalıdır. – Philip

+0

Çalışmaya iyi geliyor - oturum başlangıcını zorlar ve sonra uyarı alırsınız: session_start(): Oturum çerezi gönderilemiyor - daha önce gönderilmiş başlıklar (... Bu sayfanın aranması gereken sayfadan ajax olarak adlandırılmalı mı? en son gönderen örnek? – trainoasis

2

Okky'nin buradaki cevabıyla ilgili sıkıntı çekiyordum ve mümkün olduğunca iyi bir çalışma olmasa da bir olasılık buldum.

Facebook duvarınızın RSS beslemesini kullanın, ardından seçtiğiniz bir RSS okuyucusu ile ayrıştırın.

Here is a quick way to get your ID

+0

Besleme geçerli değil –

0

https://www.facebook.com/feeds/page.php?format=rss20&id=YOUR_UNIQUE_ID

Yani hem bana yardım, bu gibi görünecektir şeyle sona gerektiğini, Okky ve Deele cevap karıştırmak için. Ben de sonrası url bağlamak için bir çapa etiketi ekleyin: artık

<?php 
$fbApiGetPosts = $facebook->api('/YOUR_FACEBOOK_ACCOUNT_ID/feed?limit=5'); 
if (isset($fbApiGetPosts["data"]) && !empty($fbApiGetPosts["data"])) { 
    //loop through all the posts we got from facebook 
    foreach($fbApiGetPosts["data"] as $dPost){ 
     //only show posts that are posted by the page admin 
     if($dPost["from"]["id"]==$fbid){ 
      //get the post date/time and convert to unix time 
      $dTime = strtotime($dPost["created_time"]); 
      //format the date/time into something human readable 
      //if you want it formatted differently look up the php date function 
      $myTime=date("M d Y h:ia",$dTime); 
      ?> 
       <li><a href="<?php echo($dPost["link"]); ?>"> 
             <?php echo($dPost["message"]) . "<br>" . 
             $myTime; ?></a></li> 
      <?php 
     } 
    } 
} 
?> 
+0

Neden <

+0

İlk açık etiket ve son kapanış etiketi eksik ... Yanıtı ekledim. –

İlgili konular