Monday, March 26, 2012

Missing 'type' field from Facebook Graph API result

Last Friday I have joined Facebook Mobile Hack event which held at Hong Kong. I have learnt alot and want to build something by Facebook Graph API for fun. The first thing I have to try is retrieving my feed in Facebook. However I found that if I retrieving the information from the Facebook Graph API Explorer it return a 'type' field for the post such as status, link, video, checkin, etc, but the 'type' field is missing if I use Javascript SDK to retreive the post.

After do some googling, I found out the answer and I think it's worth to share. Just add "?metadata=true" at the end of query will work fine.


<html>
<head>
  <title>Testing</title>
  <link rel="stylesheet" type="text/css" href="style.css">
  <meta name="viewport" content="initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
</head>
<body>

<div id="fb-root"></div>

<script>
(function() {
  var e = document.createElement('script'); e.async = true;
  e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
  document.getElementById('fb-root').appendChild(e);
}())

window.fbAsyncInit = function() {
  FB.init({ appId: 'YOUR_APP_ID',
  status: true,
  cookie: true,
  xfbml: true,
  oauth: true})
checking();
};

function checking() {
  FB.api('/414866888308?metadata=true', function(response) { // retrieving checkin ID
    // the response.type come out finally
  
  });
}


function login() {
  FB.login(function(response) { }, {scope:'user_likes'});
}

</script>
</body>
</html>
 


Here is the book you may feel interested:
Related Posts Plugin for WordPress, Blogger...