2011-04-22 120 views
0

我使用下列獲得APPTOKENFacebook應用程序問題

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/oauth/access_token?client_id='.$config->getAppId().'&client_secret='.$config->getAppSecret().'&grant_type=client_credentials&scope=offline_access'); 

curl_setopt($ch, CURLOPT_FRESH_CONNECT, true); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_HEADER, false); 
$app_token= curl_exec($ch); 
curl_close($ch); 

並使用圖形API使用擺脫請求ID信息下面的代碼片段

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);  
curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/'.$requestId.'?'.$app_token); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_HEADER, false); 
$request= curl_exec($ch); 

curl_close($ch); 

一切工作正常,除了在IE中。 ..

當在IE中使用我的應用程序我在日誌中得到以下錯誤

PHP致命錯誤:未捕獲OAuthException:必須使用活動訪問令牌來查詢有關當前用戶的信息。 ?
facebook.php扔在管線560,
引用者:HTTP:// < my_url> request_ids = 1934696176864 & REF =通知符& notif_t = app_request

EDIT - 完整代碼

<?php 
    include './facebook.php'; 
    include './config.php'; 
    include './database.php'; 

    $config = new Config(); 
    $database = new Database(); 
    $facebook = new Facebook(array(
     'appId' => $config->getAppId(), 
     'secret' => $config->getAppSecret(), 
     'cookie' => false, 
    )); 

$sent_to_id=''; 
if(isset($_GET['request_ids']) && !empty($_GET['request_ids'])){ 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/oauth/access_token?client_id='.$config->getAppId().'&client_secret='.$config->getAppSecret().'&grant_type=client_credentials&scope=offline_access'); 
    curl_setopt($ch, CURLOPT_FRESH_CONNECT, true); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_HEADER, false); 
    $app_token= curl_exec($ch); 
    curl_close($ch); 
    echo 'Acces_Token: '.$app_token .", Session Acces Token: ".$session['access_token']; 

    //$app_token = file_get_contents('https://graph.facebook.com/oauth/access_token?client_id='.$config->getAppId().'&client_secret='.$config->getAppSecret().'&grant_type=client_credentials'); //Get application token 
    $sent = explode(',', $_GET['request_ids']); //Convert csv to array 
    $count = count($sent); //count how many objects in array 
    for ($a = 0; $a < $count; $a++) { 
     $ch = curl_init(); 
     curl_setopt($ch, CURLOPT_FRESH_CONNECT, true); 
     curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/'.$sent[$a].'?'.$app_token); 
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
     curl_setopt($ch, CURLOPT_HEADER, false); 
     $request= curl_exec($ch); 
     curl_close($ch); 

     //$request = file_get_contents('https://graph.facebook.com/'.$sent[$a].'?'.$app_token); 
     preg_match("/\"to\":\{\"name\":\"(.*?)\",\"id\":\"(.*?)\"/i", $request, $getInfo); 
     echo "sent[.".$a."] : ". $sent[$a] .", getInfo[1]: " . $getInfo[1] . ", getInfo[2]: ". $getInfo[2] ; 
     echo ", AppToken: ".$app_token; 
     $sent_to_name_temp= $getInfo[1]; 
     $sent_to_id_temp = $getInfo[2]; 

     if(!empty($sent_to_name_temp) && !empty($sent_to_id_temp)){ 
       $sent_to_id .= $getInfo[2] . ','; 
     } 
    } 
} 
$sent_to_id = substr($sent_to_id, 0 , strlen($sent_to_id)); 
$userIds = explode(',', $sent_to_id); 

$database->insert_invites($_GET['id'],$_GET['request_ids'], $userIds); 
?> 

客戶端代碼

 function showInvite(invitedby) { 
      FB.ui({ 
       method: "apprequests", 
       message: "Hey this is just for a testing App!", 
       data: "accepted", //This will be passed back to you when a user accepts the request 
       title: "Title wil be here!" 
      }, 
      function(response) { 
       if (response && response.request_ids) { 
        ajaxRequest(invitedby, response.request_ids); 
        $(".message").html("Your invitation has been sent"); 
       } else { 
        //alert('You must select some friends to send invitation!'); 
       } 
      }); 
     } 
     function ajaxRequest(invitedby, requestIds){ 
      $.ajax({ 
       url:"insertInvites.php?id=" + invitedby +"&request_ids="+requestIds, 
       success:function(){ 
        //alert("Successfully inserted into table"); 
       }, 
       failure:function(){ 
        //alert("Error while insertting into database"); 
       } 
      }); 
     } 
+0

這是完整的代碼?嘗試添加如何設置'$ requestId'變量。你還正在做其他FB電話嗎? – ifaour 2011-04-22 08:58:46

回答

0

您的PHP正在服務器上運行,而不是在瀏覽器中運行。你需要檢查你從一個特定的瀏覽器(IE)得到的輸入,並找出錯誤。

+0

我錯誤地回滾你的改變,無法弄清楚你改變了什麼。對不起 – Urvish 2011-04-22 06:37:47

+0

恩,你的整篇文章格式不正確。我通過重新應用正確的格式再次清理它。 – 2011-04-22 06:39:54

+0

感謝您的更正 – Urvish 2011-04-22 06:43:25

0

我與IE9類似的問題,我的畫布上的應用程序,因爲IE9在默認情況下拒絕第三方的cookies沒有一個適當的緊湊隱私政策的。

這個固定我的IE的特定問題)

首標( 'P3P:CP = 「IDC DSP COR ADM德維戴氏PSA PSD IVAi IVDI CONI HIS OUR IND CNT」');