2012-08-14 74 views
-1

我想發佈到用戶的活動Feed',但我不明白如何。如何使用他的Facebook圖形API訪問令牌

這裏是我的演示應用程序: 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> 

我收到錯誤:

This method must be called with an app access_token

如果我禁用的access_token在應用程序的設置,然後它說是這樣的:

You must use an access_token to access the users account details

誰能幫助?

回答

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> 
0

錯誤是在功能:後覽()。 當我在我loged我已經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); 
     }); 
:使用另一個說的access_token已經過期 AAAFIDJXVUKcBABpW5pcU97CC7sTwdDmJykOKhZAykZC6D8gaTumTsDZBRzCfJ3eqc58R5whIFuGTBnPeeRGmn6N0ccBDLRGNKXJmy5ZCexTvjBqExTmI

但功能覽()