2010-10-24 20 views
6

Sayfayı sitemde yayınlamak istiyorum. . Dokümantasyonda bana yardımcı olabilecek hiçbir şey bulamadım. Ayrıca google sonuçlarından hiçbiri mi cevap vermedi.Sayfanın başı "PHP SDK ile

function post_facebook($data=null){ 
     $result = ""; 
     require_once (ROOT. "/apps/configuration/models/ConfigurationItem.php"); 
     require_once (ROOT . "/components/facebook/facebook.php"); 

     $this->ConfigurationItem = new ConfigurationItem($this->getContext()); 

     $row=$this->ConfigurationItem->findByCatKeyItemKey('system','facebook_login'); 
     $apiid=$row['value']; 

     $row=$this->ConfigurationItem->findByCatKeyItemKey('system','facebook_pass'); 
     $secret=$row['value']; 

     $facebook = new Facebook(array(
      'appId' => $apiid, 
      'secret' => $secret, 
      'cookie' => true, 
     )); 

     $session = $facebook->getSession(); 
     print_r($session); 
     $me = null; 
     if ($session) { 
      try { 
       $uid = $facebook->getUser(); 
       $me = $facebook->api('/me'); 
      } catch (FacebookApiException $e) { 
       error_log($e); 
      } 
      $message=$data['facebook_text']; 
      $attachment = array(
       'message' => $data['facebook_text'], 
       'name' => $data['name'], 
       'link' => $this->getLinkToLatestNews(), 
       'description' => '', 
      ); 

      if($data['thumb_file_tree_id'] !== NULL) $attachment = $_SERVER['HTTP_HOST']."media/file/image_by_id/".$data['thumb_file_tree_id']."/?w=400&h=500"; 

      try { 
       $facebook->api('/162618213751448/feed/', 'post', $attachment); 
       $result = "Facebook: Sent"; 
      } catch (FacebookApiException $e) { 
       $result = "Facebook: Failed"; 
       error_log($e); 
      } 
     } else { 
      $login_url = $facebook->getLoginUrl(); 
      header("Location: ".$login_url); 
      exit; 
     } 

     return $result; 

    } 

yanlış parçasıdır:

$session = $facebook->getSession(); 
$me = null; 
if ($session) { 
    (...) 
} else { 
$login_url = $facebook->getLoginUrl(); 
    header("Location: ".$login_url); 
    exit; 
} 

Ben kullanıcı belirtilen FB hesabını (bu sayfayla) giriş yapılmasını ve ardından göndermesine izin istiyorum. Uygulama ayarları yalnızca bu hesabın yayınlanmasına izin veriyor, bu yüzden tamam olmalı ... Ama değil. FB hesabını kapattığımda, oturum hala var, ancak istisna döndürüyor. Sorun nedir?

cevap

16

Eğer yöneticisinin .. sonraki

  1. Başvurunuz bu izin minimum olması gerekir yapmak olan bir fan sayfasında yayınlamak istiyorsanız:

    $this->loginUrl = $this->facebook->getLoginUrl(
          array(
           'scope'   => 'manage_pages,offline_access,publish_stream', 
           'redirect_uri' => $url, 
          ) 
        ); 
    
  2. sen kaydedilir sonra içine:

    //get pages or applications where you are administrator 
    $accounts = $this->facebook->api('/me/accounts'); 
    
    //page where i want to post 
    $page_id = '227870047252297'; 
    
    foreach($accounts['data'] as $account) 
    { 
        if($account['id'] == $page_id) 
        { 
         $token = $account['access_token']; 
        } 
    } 
    
    
    $attachment = array(
         'access_token' => $token, 
         'message' => 'mensaje', 
         'name' => 'titulo', 
         'link' => 'http://...', 
         'description' => 'xxxxx', 
         'picture'=> 'http://...', 
    ); 
    
    
    try{ 
    $res = $this->facebook->api('/'.$page_id.'/feed','POST',$attachment); 
    
    } catch (Exception $e){ 
    
        echo $e->getMessage(); 
    } 
    
+0

teşekkür! Mükemmel. – Memochipan

1

Eğer bunu doğru anlıyorsam, giriş yaptıklarında web siteniz üzerinden uygulamanıza bağlanan kullanıcının duvarına mesaj göndermek istersiniz? Eğer öyleyse, bunu deneyin. Sürekli gönderme önlemek için komut dosyasını yeniden işleyin, ancak bu model, teoride, çalışmalıdır. yerine buraya

if ($session) { 
     try { 
      $uid = $facebook->getUser(); 
      $me = $facebook->api('/me'); 

// Yeri mesajlaşma bölümü. kullanıcı uygulama ile bağlantılı ve oturum geçerlidir eğer

$message = $facebook->api('/me/feed', 'post', array(
                  'message'=> '<Message>', 
                  'picture' => '<Picture URL>', 
                  'link'=> '<URL>', 
                  'description'=>'Description', 
                  'name'=> '<Name of Post>', 
                  'privacy'=> '<ALL_FRIENDS (Default)>', 
                  'caption'=> '<Caption>',               

                  ) 
            ); 

      } catch (FacebookApiException $e) { 
       error_log($e); 
      } 

Yani, otomatik olarak haber yem (Duvar) için yazılan gönderir.

İlgili konular