2013-02-11 127 views
1

我在Facebook上創建了一個應用程序。現在我想在Facebook牆上張貼消息。由於我是應用程序的開發人員,當我登錄到我的Facebook帳戶時,消息即將出現在我的牆上,但是當我登錄另一個用戶時,此應用程序沒有得到,頁面正在重定向到http://www.facebook.com/4oh4.php。下面在Facebook牆上發佈消息

$facebook = new Facebook(array(

      'appId' => myAppId, 
      'secret' => myAppSecret, 
       'cookie' => true, 
       'req_perms' => 'email,read_stream,read_friendlists,publish_stream,offline_access,manage_pages' 

     )); 
    $user = $facebook->getUser(); 
$app_id = myAppId; 
     $canvas_page = "https://apps.facebook.com/apptestingas/"; 
     $auth_url = "http://www.facebook.com/dialog/oauth?client_id=" 
      . $app_id . "&redirect_uri=" . urlencode($canvas_page)."&scope=email,read_stream,read_friendlists,publish_stream,offline_access,manage_pages"; 
if(isset($_REQUEST["signed_request"])) 
    { 
     $signed_request = $_REQUEST["signed_request"]; 
     list($encoded_sig, $payload) = explode('.', $signed_request, 2); 
     $data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true); 

    } 
     if (empty($data["user_id"])) 
    { 
     echo("<script> top.location.href='" . $auth_url . "'</script>"); 

    } 
    else 
    { 
     $uid = $data["user_id"]; 

    } 
try { 
    // Proceed knowing you have a logged in user who's authenticated. 
echo $token = $facebook->getAccessToken(); 
$user_profile = $facebook->api('/'.$uid.'',array (
'access_token' => $token) 
); 


    } catch (FacebookApiException $e) { 
    error_log($e); 
    $user = null; 
    } 
    if (!empty($user_profile)) { 
     # User info ok? Let's print it (Here we will be adding the login and registering routines) 

     echo $username = $user_profile['name']; 
    $uid = $user_profile['id']; 
$facebook->api('/'.$uid.'/feed', 'post', array(
      'message' => "sdsgdg testingbbbb", 

    )); 
    } 

我的代碼被賦予取悅任何一項幫助

+0

必須通過這個美好和輕鬆一展身手的馬哈茂德·阿赫桑理解文章。肯定會幫助你。 http://thinkdiff.net/facebook/php-sdk-graph-api-base-facebook-connect-tutorial/ – 2013-02-11 10:30:26

回答

1

是您的應用程序設置的沙盒模式?這是可以在應用程序設置中控制的。 引用描述:「如果啓用,只有應用程序開發人員將能夠使用應用程序」。

+0

當我關閉然後我得到錯誤的** SSL連接錯誤** – sreelatha 2013-02-11 10:47:10

+0

好吧,我現在只是猜測,但如果將'$ auth_url'協議更改爲https,會發生什麼? – 2013-02-11 12:22:07