-1

我正在尝试向用户发布“活动提要”,但我不明白如何。

这是我的演示应用程序:http: //bazaar-market.co.uk/facebook_test/car.html

您可以查看源代码以查看所有代码,因为它都是 HTML。

<script type="text/javascript">
  function postView()
  {
      FB.api(
        '/me/fandango-auctions:view',
        'post',
        { item : 'http://bazaar-market.co.uk/facebook_test/car.html' },
        function(response) {
           if (!response || response.error) {
              alert("Error");
           } else {
              alert('View was successful! Action ID: ' + response.id);
           }
           console.log(response);
        });

  }
</script>

我收到错误消息:

必须使用应用程序 access_token 调用此方法

如果我在应用程序的设置中禁用 access_token,那么它会说:

您必须使用 access_token 访问用户帐户详细信息

任何人都可以帮忙吗?

4

2 回答 2

0

尝试这个。

https://developers.facebook.com/docs/authentication/client-side/

<html> 
   <head> 
     <title>Client-side OAuth Example</title> 
   </head> 
   <body> 
   <script> 
     function displayUser(user) {
       var userName = document.getElementById('userName');
       var greetingText = document.createTextNode('Greetings, '
         + user.name + '.');
   userName.appendChild(greetingText);
     }

     var appID = YOUR_APP_ID;
     if (window.location.hash.length == 0) {
       var path = 'https://www.facebook.com/dialog/oauth?';
   var queryParams = ['client_id=' + appID,
     'redirect_uri=' + window.location,
     'response_type=token'];
   var query = queryParams.join('&');
   var url = path + query;
   window.open(url);
     } else {
       var accessToken = window.location.hash.substring(1);
       var path = "https://graph.facebook.com/me?";
   var queryParams = [accessToken, 'callback=displayUser'];
   var query = queryParams.join('&');
   var url = path + query;

   // use jsonp to call the graph
       var script = document.createElement('script');
       script.src = url;
       document.body.appendChild(script);        
     }
   </script> 
   <p id="userName"></p> 
   </body> 
  </html>
于 2012-08-14T13:40:07.750 回答
0

错误在函数中:postView()。当我登录时,我有 access_token : AAAFIDJXVUKcBABpW5pcU97CC7sTwdDmJykOKhZAykZC6D8gaTumTsDZBRzCfJ3eqc58R5whIFuGTBnPeeRGmn6N0ccBDLRGNKXJmy5ZCexTvjBqExTmI

但是函数 postView() 使用另一个已经过期的 access_token :

FB.api(
        '/me/fandango-auctions:view',
        'post',
        {
        access_token : 'AAAFIDJXVUKcBALARwKxJHdwwf7chdqleGsrQtYsIk3xiB4vR111s3Gc4cos3Dgd6CFynoUURci0i3t7lzh5mZA41UqSJzbccjy6JjWLSTk8UfgvEO',
        item : 'http://bazaar-market.co.uk/facebook_test/car.html' 
        },
        function(response) {
           if (!response || response.error) {
              alert("Error");
           } else {
              alert('View was successful! Action ID: ' + response.id);
           }
           console.log(response);
        });
于 2012-08-14T15:59:46.133 回答