2011-05-01 55 views
0

我試圖將我的web應用程序與Facebook平臺集成。Facebook應用程序開發 - 使用對話框API進行身份驗證使用PHP

下面

是我的測試代碼,

if ($_REQUEST['error_reason']) { echo("<script> top.location.href='http://facebook.com'</script>"); } 
else { 
    $app_id = "APP_CODE"; 
    $canvas_page = "https://e3xcp.com/hs/fb/"; 
    $auth_url = "http://www.facebook.com/dialog/oauth?client_id=" . $app_id . "&redirect_uri=" . urlencode($canvas_page) "&scope=email,user_birthday,user_hometown,user_location,user_religion_politics,user_website,user_checkins"; 

    $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 { 
      echo ("Welcome User: " . $data["user_id"] . "<BR><BR>"); 
      print_r($data); 
      echo "<BR><BR>". $data['oauth_token'] . "<BR><BR>"; 

      $graph_url = "https://graph.facebook.com/me?access_token=". trim($data['oauth_token']); 
      $json_data = file_get_contents($graph_url); 
      $me = json_decode($json_data); 
      echo $me->id; 
    } 
} 

有兩個問題,

  1. 時進行身份驗證(新用戶),當用戶按「允許」按鈕,瀏覽器導航回在我的畫布頁面和Facebook服務器之間。

  2. 當通過身份驗證的用戶訪問的應用程序,我得到一個錯誤的說法,

    **> Warning: file_get_contents(https://graph.facebook.com/me?access_token=200335043341031|2.axhed5PlPjICLqIN2ElgGA__.3600.1304254800.1-100001278552830|ez-LK5f_ymd-q9Ju4qa7zAvjEgo) [function.file-get-contents]: failed to open stream: No error in C:\Inetpub\vhosts\E3XCP.COM\httpdocs\hs\FB\index.php on line 19** 
    

但是當我複製並粘貼GRAPH URL

***https://graph.facebook.com/me?access_token=200335043341031|2.axhed5PlPjICLqIN2ElgGA__.3600.1304254800.1-100001278552830|ez-LK5f_ymd-q9Ju4qa7zAvjEgo*** it returns the correct output 

有兩種認證樣本在Facebook開發者文檔中給出,我嘗試了兩種方法。

該應用的鏈接是http://apps.facebook.com/slhoroscope 幫助!!!

回答

1
  1. 您需要使用畫布頁面,而不是畫布網址,即$canvas_page = "http://apps.facebook.com/slhoroscope/";
  2. 它是與你的PHP配置,最有可能的OpenSSL的擴展。
+0

我該如何檢查? – megazoid 2011-05-01 13:03:40

+1

@megazoid:我想'<?php phpinfo(); ?>'。至於如何安裝它,你需要檢查與環境支持論壇/教程(xampp,wampserver ...無論你已經安裝在你的機器上) – ifaour 2011-05-01 13:10:07

+0

ifaour,謝謝很多隊友...第一個問題是排序(網址導航問題)後使用應用程序的網址,而不是我的網址。這是facebook文檔中留下的關鍵信息之一.. – megazoid 2011-05-01 13:11:53

相關問題