How to use access tokens with he Facebook Graph API

I am trying to post to a users 'Activity Feed' but I don't understand how.

Here is my demo application: http://bazaar-market.co.uk/facebook_test/car.html

You can view the source to see all the code as it's all 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>

I am getting the error:

This method must be called with an app access_token

If I disable access_token's in the app's settings then It says something like:

You must use an access_token to access the users account details

Can anyone help?

Answers


Try this.

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>

Error is in function : postView(). When i am loged in I have access_token : AAAFIDJXVUKcBABpW5pcU97CC7sTwdDmJykOKhZAykZC6D8gaTumTsDZBRzCfJ3eqc58R5whIFuGTBnPeeRGmn6N0ccBDLRGNKXJmy5ZCexTvjBqExTmI

but function postView() using another access_token that already expired:

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);
        });

Need Your Help

Android: Showing array list item to listView

android listview

I am new to android , I have an arraylist but I want to show its value in a ListView ,but I am unable to do that.I have searched many methods like ArrayAdapter and BaseAdapters etc.but not helpful....