Jump to content

FB SDK Issues, missing, but not missing..


DIY-Forum

Recommended Posts

Hey everyone!

I am now very frustrated with this code, been on it for hours trying to get it to work. And have searched everywhere for a good tutorial or example on how to connect to fb, but it just won't work with this FB graph library, It loads the like feature GUI, from the SDK CSS "compiler" but it won't recognize the FB.api load. and says no fb sdk loaded anyway so my debugging feature kinda mess my head up even more..

 

Also this is basically copy and paste from Facebooks own developer guiding sites and the FB.api bit is directly from the copy board of a tested api get call on fbs own dev site so I am as lost as I can get..

What I want to get is basically the output of likes which, if this was working would be returned as a json response

here's my code:

<html><head>
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : 'myappid',
      xfbml      : true,
      version    : 'v2.8'
    });
  };


  (function(d, s, id){
     var js, fjs = d.getElementsByTagName(s)[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement(s); js.id = id;
     js.src = "//connect.facebook.net/en_US/sdk.js";
     fjs.parentNode.insertBefore(js, fjs);
   }(document, 'script', 'facebook-jssdk'));


if (typeof(FB) != 'undefined' && FB != null ) {    
  FB.api(
    '/mypost/reactions',
    'GET',
    {},
    function(response) {
        document.getElementById("content").innerHTML = response;
    }
  );
} else {
    alert("no fb sdk loaded");
}
</script>
</head>
<body>
<div id="content"></div>
<div
  class="fb-like"
  data-share="true"
  data-width="450"
  data-show-faces="true">
</div>
</body>
</html>

Thanks for any help, link, or whatever you've got! :)

Kristian

Link to comment
Share on other sites

Thank you, that seems to have solved something.

 

It does not give any errors, but nothing is showing either, the FB like buttons have dissapeared and the code inspector console tells me nothing so it seems to be ok.

Could this have to do with me not calling the right response "type"?

 

I have not much experience with json, but I thought that placing the response to innerHTML of content should give a result.

 

I do not know how they output it, but the result in the fb dev console is like this,

{
  "data": [
    {
      "id": "posterid",
      "name": "postername",
      "type": "LIKE"
    },
    plus many more rows like it

Thanks

Link to comment
Share on other sites

Have read it like 5-6 times already.


Multiple ID Read Requests

You can make a single GET request that retrieves multiple nodes by using the ?ids endpoint with the object IDs of those nodes. For example, to lookup the Facebook Developers page and the current session user in a single request, you could use the following Graph API call:

GET graph.facebook.com
/?ids=platform,me

Which is equivalent to the following individual API requests:

GET graph.facebook.com
/platform

GET graph.facebook.com
/me
The returned data will look something like this:
{
"me": {
"id": "1234567890"
... // Other fields
}, 
"platform": {
"id": "19292868552"
... // Other fields
}
}

but thanks, sure I'll figure it out eventually. just not in JS.

Link to comment
Share on other sites

Sort of got it working... You had it right, but it could not be in the async, had to set a timeout:
And the way of calling json was not right, had to change to get any result other than object object. (that probably says itself to most people)

Anyways would not have done it without the help with the halway loaded js script.
.
Thanks for helping.

Kristian

Edited by DIY-Forum
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...