2015-11-13 104 views
-1

我無法弄清楚如何更改這個簡單的代碼以使用最新的facebook SDK ... 看起來他們已經改變了一些變量以及檢索信息的方式。我之前沒有和facebook SDK一起工作過,在編程方面不太好。準備好文檔並嘗試了幾件事情後,我仍然失敗。所以,我希望一些你們可以幫助我在這裏...將php更改爲新的facebook SDK

require("src/facebook.php"); 

// construct the object with your facebook app data 
$facebook = new Facebook(array(
'appId' => '[YOUR APP ID]', 
'secret' => '[YOUR APP SECRET ID]', 
'cookie' => true 
)); 

try { 
    // to get the id of the currently logged in user 
    // if, you want you can manually set a user id here like this: 
    //$uid = '[FB USER ID]'; 
    $uid = $facebook->getUser(); 

    // if you know know the access token before hand then you can set it here 
    // or you can leave this line commented 
    //$facebook->setAccessToken([ACCESS TOKEN FOR THIS USER - APP]); 

    $api_call = array(
     'method' => 'users.hasAppPermission', 
     'uid' => $uid, 
     'ext_perm' => 'publish_checkins' 
    ); 
    $can_post = $facebook->api($api_call); 
    if ($can_post) { 
     $facebook->api('/'.$uid.'/checkins', 'POST', array(
     'access_token' => $facebook->getAccessToken(), 
     'place' => '[LOCATION ID]', 
     'message' => 'I am place to check in', 
     'picture' => 'http://test.com/someplace.png', 
     'coordinates' => json_encode(array(
      'latitude' => '[LATITUDE]', 
      'longitude' => '[LONGITUDE]', 
      'tags' => '[A LIST OF TAGS TO USE FOR THIS CHECKIN]')) 
     )); 
     echo 'You are checked in'; 
    } else { 
     die('Permissions required!'); 
    } 
} catch (Exception $e){ 
    // No user found - ask the person to login 
    $login_url = $facebook->getLoginUrl(); 
    header("Location: ".$login_url); 
} 
+1

那麼,什麼是錯誤? – Peter

回答

0

什麼代碼要達到的目的是不可能的了:https://developers.facebook.com/docs/graph-api/reference/v2.5/user/checkins

This endpoint is removed as of Graph API version 2.0

只能通過獲取用戶簽到/me/feed enpoint,因爲checkins現在只是一個地方的狀態帖子。

+0

哦,我看到了...你能幫我用一個代碼來通過新的API登入嗎? –

+0

在文檔中有示例代碼:https://developers.facebook.com/docs/graph-api/reference/v2.5/user/feed#publish – luschn

+0

只需看看參數,就有地方。這只是一個地方的簡單ID。 – luschn