2012-05-15 7 views
1

제발 도와주세요. 나는 이것을 거의 1 달 동안 ... 나는 메시지와 데이터를 검색하고 싶다. 나는 최신 FB API를 사용하여 최선을 다했다. 나는 틀린 것을 발견 할 수 없었다. 또한 나는 탐닉 할 수 없다. user_id .. 콜백 기능에는 어떤 조치가 필요합니까?facebook user_id 항상 0을 반환합니다

앱 URL이 :이

<?php 
    session_start(); 
    if(!empty($_REQUEST['request_ids'])) { 
    require_once('src/facebook.php'); 

    $config = array(); 
    $config["appId"] = "XXXXXXXX"; 
    $config["secret"] = "XXXXXXXXXXXX"; 
    $config["fileUpload"] = false; // optional 

    // Create our Application instance. 
    $facebook = new Facebook(array(
     'appId' => $config["appId"], 
     'secret' => $config["secret"], 
     'cookie' => true, 
    )); 

     $user_id= $facebook->getUser(); 

    if($user_id){ 
     try { 

      $app_token = $facebook->getAccessToken(); 

      $requests = explode(',',$_REQUEST['request_ids']); 
      foreach($requests as $request_id) { 

      $data = $facebook -> api('/'.$user_id.'/apprequests?'.$app_token); 

      //you will delete the request here 
      $delete_url = "https://graph.facebook.com/".$request_id."_".$user_id."?".$app_token."&method=delete"; 
      $result = file_get_contents($delete_url); 
     } 

     } catch (FacebookApiException $e) { 
     error_log($e); 
     $user = null; 
     } 
    }else{ 
    ?> 

    <script> 
     var oauth_url = 'https://www.facebook.com/dialog/oauth/'; 
     oauth_url += '?client_id=XXXXXXXXXX'; 
     oauth_url += '&redirect_uri=' + encodeURIComponent('https://apps.facebook.com/greetingz/'); 
     oauth_url += '&scope=user_birthday,user_events' 
     window.top.location = oauth_url; 
    </script> 

    <?php 
    }; 
    } 

    else{ 


    ?> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <script src="http://connect.facebook.net/en_US/all.js"></script> 
    <script src="js/jquery-1.6.2.min.js" type="text/javascript" ></script> 
    <script src="Scripts/swfobject_modified.js" type="text/javascript"></script> 
    <link rel="stylesheet" type="text/css" href="css/style.css"/> 
    <title>Greetings</title> 

    </head> 

    <body> 

    <div align="center"> 
     <object id="FlashID" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="664" height="626"> 
     <param name="movie" value="flash/Candle_jey.swf" /> 
     <param name="quality" value="high" /> 
     <param name="wmode" value="opaque" /> 
     <param name="swfversion" value="6.0.65.0" /> 
     <!-- This param tag prompts users with Flash Player 6.0 r65 and higher to download the latest version of Flash Player. Delete it if you don't want users to see the prompt. --> 
     <param name="expressinstall" value="Scripts/expressInstall.swf" /> 
     <!-- Next object tag is for non-IE browsers. So hide it from IE using IECC. --> 
     <!--[if !IE]>--> 
     <object type="application/x-shockwave-flash" data="flash/Candle_jey.swf" width="664" height="626"> 
      <!--<![endif]--> 
      <param name="quality" value="high" /> 
      <param name="wmode" value="opaque" /> 
      <param name="swfversion" value="6.0.65.0" /> 
      <param name="expressinstall" value="Scripts/expressInstall.swf" /> 
      <!-- The browser displays the following alternative content for users with Flash Player 6.0 and older. --> 
      <div> 
      <h4>Content on this page requires a newer version of Adobe Flash Player.</h4> 
      <p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" width="112" height="33" /></a></p> 
      </div> 
      <!--[if !IE]>--> 
     </object> 
     <!--<![endif]--> 
     </object> 

    </div> 
    <div class="main"> 

    <div style="margin-left:300px; width:540px; margin:auto;"> 

    <table> 
    <tr> 
     <td> 
      <span style="font-size:18px;font-family:'Trebuchet MS', Arial, Helvetica, sans-serif; color:#603;">Greeting :</span> 
     </td> 
     <td> 
      <textarea type="text" name="message" id="msg" style="height:40px; width:350px;" ></textarea> 
     </td> 
     <td> 
      <input type="submit" value="Send" id="one" style="color:#CCC; background-color:#603; border:none; width:80px; height:40px;" 
      onclick="sendRequestViaMultiFriendSelector(); return false;"></span> 
     </td> 
    </tr> 
    </table> 
    </div>  

    <script> 
     FB.init({ 
     appId : 'XXXXXXXXXXX', 
     status : true, 
     cookie : true, 
     frictionlessRequests: true, 
     oauth: true 
     }); 


     function sendRequestViaMultiFriendSelector() { 

     FB.ui({method: 'apprequests', 
      message: $("#msg").val(), 

     },function getMultipleRequests(requestIds) { 
      FB.api('', {"ids": requestIds }, function(response) { 
      console.log(response); 
      }); 
     }, requestCallback); 
     } 

     function requestCallback(response) { 
     // Handle callback here 
     //var requestID = FB.api("/requestID", callback); 
     alert("Post was published."); 
     } 
    </script> 

    <div id="fb"> 

    </div> 
    <?php }?> 
    </div> 
    <script type="text/javascript"> 
    swfobject.registerObject("FlashID"); 
    </script> 

    </body> 
    </html> 
+0

이것은 내 코드입니다. 제발 도와주세요 .. – Wazan

+0

$ user_id = $ facebook-> getUser(); 항상 0을 반환합니다 – Wazan

답변

3

버디 자세히 this을 읽어 내 전체 코드

입니다 https://apps.facebook.com/greetingz/에게,이 문제를 해결할 것입니다, 당신은 당신이 signed_request에서 당신이 USER_ID를 얻을 signed_request을 구문 분석 할 필요가 이 같은 서명 된 요청을 얻을 수 있습니다. authResponse.signed_request

또는 "$ user_id = $ facebook-> getUser();"대신 Facebook 그래프 API 메소드 아래에서 사용할 수 있습니다. 귀하의 코드입니다.

FB.login(function(loginResponse) { 
    if (loginResponse.authResponse) { 
     var userId = loginResponse.authResponse.userID; 

     // Work with userId here 
     var signed_request = loginResponse.authResponse.signedRequest; 
     //Work with signed request here 
    } 
    else { 
     //User cancelled login or did not fully authorize   
    } 
}); 
+0

나는 최선을 다했으나하지 못했습니다. 내가 페이스 북의 로그인 (샘플 애플 리케이션을 위해 만들어진)과 FTP를주고, u를 확인하고 전화 할 수 있습니다. 나는 거의 3 주 동안 stucke를 가지고있다. 제발 .. – Wazan

+0

대단히 고맙습니다. 마침내 고쳐 주셨습니다. Stackoverflow 주셔서 감사합니다 :) – Wazan

+2

Wazan, 나는 같은 문제가 있습니다. 어떻게 그걸 고쳤습니까? – Shubo

관련 문제