2012-09-12 71 views
0

我想知道是否有人可以幫助我。Facebook PHP SDK:發佈對象/動作

我正在嘗試使用PHP SDK發佈操作,但似乎並沒有在發出請求後返回對象,也沒有使用操作更新用戶配置文件的活動部分。我有這在JS工作正常,但似乎無法將其移動到PHP。

// include the FB SDK 
require_once(APPLICATION_PATH . '/../library/facebook/facebook.php'); 

// create the application instance 
$facebook = new Facebook(array(
    'appId' => $this->facebookConfig->appid, 
    'secret' => $this->facebookConfig->appsecret, 
    'cookie' => true 
)); 

// get the user id 
$user = $facebook->getUser(); 
if(!empty($user)) { 
    // We have a user ID, so probably a logged in user. 
    // If not, we'll get an exception, which we handle below. 
    try { 

     // post og actions 
     if(!empty($this->thanksData->ogobject) && !empty($this->thanksData->ogaction)){ 

      $method = '/me/' . $this->appData->namespace . ':' . $this->thanksData->ogaction; 
      $params = array(
         $this->thanksData->ogobject => 'http://mydomain.com/thanks', 
         //'access_token' => $this->fbAuthToken 
        ); 

      $ret_obj = $facebook->api($method, 'POST', $params); 

     } 

     // wall post 
     if(!empty($this->facebookConfig->wallmsg)) 
      $this->wallPost($facebook); 

    } catch(FacebookApiException $e) { 
     // If the user is logged out, you can have a 
     // user ID even though the access token is invalid. 
     // In this case, we'll get an exception, so we'll 
     // just ask the user to login again here. 
     $params = array(
      'scope'   => $this->permissions, 
      'redirect_uri' => $this->facebookConfig->applink 
     ); 
     $loginUrl = $facebook->getLoginUrl($params); 

     // log errors 
     error_log($e->getType()); 
     error_log($e->getMessage()); 

     // redirect if not logged in or not enough permissions 
     //echo "<script>top.location=\"".$loginUrl."\";</script>";die; 
    } 

    // Give the user a logout link 
    //echo '<br /><a href="' . $facebook->getLogoutUrl() . '">logout</a>'; 
} 

在JS 此代碼之前,我贊成在做任務的PHP

// initialise facebook 
window.fbAsyncInit = function() { 

    // get the data 
    var data = $('body').data(); 

    FB.init({ 
     appId : data.appid, // App ID 
     status : true, // check login status 
     cookie : true, // enable cookies to allow the server to access the session 
     xfbml : true, // parse XFBML 
     oauth : true // oauth stuff 
    }); 

    // enable actions on page visit 
    if(data.object.length > 0 && data.action.length > 0){ 

     // check if we have permissions 
     FB.login(function(loginResponse){ 

      FB.api('me/permissions','get',function(response){ 

       // get the data 
       var data = $('body').data(); 

       if(data.ogactions == 1){ 
        var params = {}; 
        params[data.object] = data.url; 

        // post that we read the article 
        FB.api(
         '/me/'+ data.appnamespace + ':' + data.action, 
         'post', 
         params, 
         function(response) { 
          if (!response || response.error) { 
           console.log(response); 
          } else { 
           console.log('Action successful! Action ID: ' + response.id); 
          } 
        }); 

       } 

      }); 

     }, {scope: 'publish_actions,publish_stream'}); 

    } 
} 
+0

你使用的是Zend框架 –

+0

你得到的錯誤是什麼,你可以粘貼錯誤日誌 –

+0

是的我使用的是Zend框架,錯誤日誌沒有錯誤,傾銷ret_obj什麼都不做,我必須移動在api查詢上面的轉儲,但不能轉儲實際的api請求 – gazzwi86

回答

1

這是一個相當愚蠢的錯誤的移除,它正在同的例子,我的OG元字段在頭上有name =「」而不是property =「」,這是我沒有注意到的。

相關問題