2013-08-29 30 views
3

我正在嘗試開發一個應該將新聞提要發送到網站的fb應用程序;Facebook羣組可以發送新聞Feed嗎?

我設法使用app_id和app_secret進行訂閱,但我沒有收到新聞訂閱源;

public function actionSubscription() { 
     $app_id = '691036934243090'; 
     $app_secret = 'ca6e828f41c638dba4fb0864f7d9f6e8'; 
     $app_url = 'http://www.ghidul-comercial.ro'; 
     $fields = 'feed'; 
     $verify_token = 'blabla'; 

     // Fetching an App Token 
     $app_token_url = 'https://graph.facebook.com/oauth/access_token?client_id=' 
       . $app_id . '&client_secret=' . $app_secret 
       . '&grant_type=client_credentials'; 
     $ch = curl_init(); 
     curl_setopt($ch, CURLOPT_URL, $app_token_url); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
     $res = curl_exec($ch); 
     parse_str($res, $token); 

     if (isset($token['access_token'])) { 
      // Let's register a callback 
      $params = array(
       'object' 
       => 'page', 
       'fields' 
       => $fields, 
       'callback_url' 
       // This is the endpoint that will be called when 
       // a User updates the location field 
       => $app_url . '/index.php/site/api', 
       'verify_token' 
       => $verify_token, 
      ); 

      curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/' 
        . $app_id . '/subscriptions?access_token=' 
        . $token['access_token']); 
      curl_setopt($ch, CURLOPT_POST, 1); 
      curl_setopt($ch, CURLOPT_POSTFIELDS, $params); 
      $res = curl_exec($ch); 
      if ($res && $res != 'null') { 
       print_r($res); 
      } 

      // Fetch list of all callbacks 
      curl_setopt($ch, CURLOPT_POST, 0); 
      $res = curl_exec($ch); 
     } 
     if ($res && $res != 'null') { 
      print_r($res); 
     } 
     curl_close($ch); 
     error_log('test'); 
    } 

這是我打算如何趕上飼料:

public function actionApi() { 
    $data = new Data(); 
    $data->info = '1'; 
    $data->save(false); 

    $method = $_SERVER['REQUEST_METHOD']; 
    $data = new Data(); 
    $data->info = $method; 
    $data->save(false); 

    $rawdata1 = file_get_contents('php://input'); 
    $rawdata2 = json_decode($HTTP_RAW_POST_DATA,true); 
    $rawdata2 = json_decode(file_get_contents('php://input'),true); 


    $data = new Data(); 
     $data->info = $rawdata1; 
     $data->save(false); 

    if ($method == 'GET' && isset($_GET['hub_mode']) && $_GET['hub_mode'] == 'subscribe' && isset($_GET['hub_verify_token']) && $_GET['hub_verify_token'] == 'blabla') { 
     echo $_GET['hub_challenge']; 
     exit; 
    } elseif ($method == 'POST') { 
     $post = file_get_contents("php://input"); 
     $data = new Data(); 
     $data->info = $post; 
     $data->save(false); 
    } 

    $data = new Data(); 
    $data->info = '2'; 
    $data->save(false); 
} 
+0

您將首先__do立即___重置您的應用程序儀表板中的應用程序的祕密,因爲你剛剛在這裏發佈它。 – CBroe

+0

是的,我知道關鍵;我會重置它,我得到它的工作 –

+0

重置它__now__,否則任何人都可以使用它在您的應用程序的名稱在Facebook上採取行動。 – CBroe

回答

2

link點擊Get Access Token,選擇通過單擊一切從3個選項卡,單擊獲取acccess令牌,然後再粘貼組ID;也在您的飼料領域,然後點擊提交。

就這樣!這將起作用

+0

omg,我知道它有點像那樣; 10倍指出 –

相關問題