2012-08-14 55 views
-1

任何人都可以告訴我下面的開放圖形調用代碼有什麼問題。打開圖:Java腳本:必須使用活動訪問令牌來查詢有關當前用戶的信息。

我有一個應用程序的令牌,用戶令牌與嘗試了每一次的任何令牌與響應我

{「錯誤」:{「消息」:「一個積極的訪問令牌,必須使用查詢有關信息當前用戶 「」 類型 「:」 OAuthException」, 「代碼」:2500}}

我已經經過驗證的應用令牌,用戶令牌和我的FB調試代碼

<?php 
$appId = '****************'; 
$appSecret = '*************************'; 
$appNameSpace = 'og_loctest'; 

$token_url = "https://graph.facebook.com/oauth/access_token?" . 
     "client_id=" . $appId . 
     "&client_secret=" . $appSecret . 
     "&grant_type=client_credentials"; 
$response = file_get_contents($token_url); 

$params = null; 
parse_str($response, $params); 
$access_token = $params['access_token']; 
?> 

<html xmlns:og="http://ogp.me/ns" xmlns:fb="http://www.facebook.com/2008/fbml" lang="en"> 
<head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# og_loctest: http://ogp.me/ns/fb/og_loctest#"> 
    <meta property="fb:app_id" content="<?php echo $appId;?>" /> 
    <meta property="og:type" content="og_loctest:properties" /> 
    <meta property="og:url" content="http://nirav-metronew.kwetoo.com/fbtest/" /> 
    <meta property="og:title" content="Sample Properties" /> 
    <meta property="og:image" content="https://s-static.ak.fbcdn.net/images/devsite/attachment_blank.png" /> 
    <title>OG Tutorial App</title> 
</head> 
<body> 
    <div id="fb-root"></div> 
    <script> 
    window.fbAsyncInit = function() { 
     FB.init({ 
     appId  : "<?php echo $appId;?>", 
     status: true, 
     cookie: true, 
     xfbml: true, 
     frictionlessRequests: true, 
     useCachedDialogs: true, 
     oauth: true 
     }); 
    }; 

    // Load the SDK Asynchronously 
    (function(d){ 
     var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;} 
     js = d.createElement('script'); js.id = id; js.async = true; 
     js.src = "//connect.facebook.net/en_US/all.js"; 
     d.getElementsByTagName('head')[0].appendChild(js); 
    }(document)); 

    function fblogin() 
    { 
     FB.login(function(response) { 
      if (response.authResponse) { 
      postProperties(); 
      } 
     },{scope: 'email,offline_access,publish_stream,publish_actions'}); 
    } 

     function postProperties() 
     { 

      FB.api(
      '/me/og_loctest:post', 
      'post', 
      { properties: 'http://nirav-metronew.kwetoo.com/fbtest/',access_token:"<?php echo $access_token;?>"}, 
      function(response) { 
       if (!response || response.error) { 
        alert('Error occured'); 
       } else { 
        alert('Facebook open graph tested! Action ID: ' + response.id); 
       } 
      }); 
     } 
    </script> 
</head> 
<body> 
    <form> 
    <input type="button" value="Post properties" onclick="fblogin()" /> 
    </form> 
</body> 
</html> 

回答

1

可以在任何一個告訴我下面的開放圖的代碼有什麼問題呼叫。

你的腳本邏輯是有缺陷的 - 因爲你混淆發生了什麼客戶端和服務器什麼方,並

 FB.api(
     '/me/og_loctest:post', 
     'post', 
     { properties: 'http://nirav-metronew.kwetoo.com/fbtest/', 
      access_token:"<?php echo $access_token;?>"}, 

您在FB.login的回調中調用此客戶端。如果用戶剛剛登錄,那麼早先在服務器上運行的PHP 無法知道剛剛導致客戶端登錄的當前訪問令牌。 PHP無法展望未來......因此,最終在這個地方放出什麼東西,它肯定不會成爲您認爲它的當前訪問令牌。

但JS SDK完全有能力處理它的訪問令牌本身,因此您不必將其作爲參數明確地傳遞給此API調用 - 只需完成部分access_token:"…"即可。

+0

謝謝回答我的闕.. 是的,你是對的人,但我通過應用程序和的access_token,因爲我覺得應用程序的訪問令牌不依賴於用戶會話 通過你所提到的什麼,我得到了我曾嘗試方式這是我fb通話的迴應。 {「error」:{「message」:「(#15)此方法必須使用應用程序access_token進行調用。」,「type」:「OAuthException」,「code」:}} – 2012-08-14 11:45:39

+1

您無法訪問在使用應用程序訪問令牌時使用'/ me/...'圖形API,因爲API無法知道「我」應該是誰。改爲使用'/ userid/...'調用。 – CBroe 2012-08-14 11:51:03

+0

哇,真的你很棒.....這真的對我有用:) 非常感謝.. – 2012-08-16 07:37:11

相關問題