javascript 必须使用主动访问令牌来查询有关具有开放图的当前用户的信息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11781123/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 14:19:17  来源:igfitidea点击:

An active access token must be used to query information about the current user with open graph

javascriptfacebookfacebook-graph-api

提问by MGE

Hello everyone I'm trying to post the activity of users of my facebook app, I follow the tutorial step by step but it doesn't work properly...

大家好,我正在尝试发布我的 facebook 应用程序用户的活动,我一步一步地按照教程进行操作,但它无法正常工作...

The alert message show me the error "Error occured An active access token must be used to query information about the current user" why?? I'm loged correctly.

警报消息向我显示错误“发生错误,必须使用活动访问令牌来查询有关当前用户的信息”为什么?我登录正确。

The code is this:

代码是这样的:

<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US"
  xmlns:fb="https://www.facebook.com/2008/fbml"> 
<head prefix="og: http://ogp.me/ns# appnamespace: 
              http://ogp.me/ns/apps/appnamespace#">
 <title>OG Tutorial App</title>
   <meta property="fb:app_id" content="appID" /> 
   <meta property="og:type" content="appnamespace:recipe" /> 
   <meta property="og:title" content="Stuffed Cookies" /> 
   <meta property="og:image" content="http://www.domain.com/logo.gif" /> 
   <meta property="og:description" content="The Turducken of Cookies" /> 
   <meta property="og:url" content="http://www.domain.com/activity.php">

   <script type="text/javascript">
   function postCook()
   {
       FB.api(
         '/me/namespace:cook',
         'post',
         { recipe: 'http://www.domain.com/activity.php' },
         function(response) {
            if (!response || response.error) {
               alert('Error occured '+ response.error.message); // it shows "Error occured An active access token must be used to query information about the current user." message
            } else {
               alert('Cook was successful! Action ID: ' + response.id);
            }
         });
   }
   </script>
 </head>
 <body>
   <div id="fb-root"></div>
   <script>
     window.fbAsyncInit = function() {
       FB.init({
         appId      : 'appID', // App ID
         status     : true, // check login status
         cookie     : true, // enable cookies to allow the server to access the session
         xfbml      : true  // parse XFBML
       });
     };

     // 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));
   </script>

   <h3>Stuffed Cookies</h3>
   <p>
     <img title="Stuffed Cookies" 
          src="http://www.domain.com/logo.gif" 
       />
   </p>

   <br>
   <form>
<input type="button" value="Cook" onclick="postCook()" />
  </form>
</body>
</html>

回答by Tchoupi

I don't see anywhere in your source where you authenticate the user. The user must authorize your application first, as described here: https://developers.facebook.com/docs/authentication/client-side/

我在您的来源中没有看到您对用户进行身份验证的任何地方。用户必须首先授权您的应用程序,如下所述:https: //developers.facebook.com/docs/authentication/client-side/