简体   繁体   中英

facebook graph api using javascript

I am using this code to get the posts of a page in api in javascript but it isn't working the FUNCTION FB.API IS NOT BEING INVOKED.

window.fbAsyncInit = function() {
FB.init({
  appId      : 'xxxxxxxxxxxxxx',
  xfbml      : true,
  version    : 'v2.9'

});

};

(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'));

function abdul(){

alert('working');

FB.api('EuropeanCommission/posts', GET, function(response) {

        var output="<ul>";

    for (var i in mydata.data) {

        output+="<li>"+mydata.data[i].message;

    }

    output+="</ul>";

    document.getElementById("placeholder").innerHTML=output;   });

};

You didn't put param field in your api call and GET should be in the single quote ' ':

FB.api('EuropeanCommission/posts', GET, function(response) {      

});

You should do:

FB.api('EuropeanCommission/posts', 'GET', {} , function(response) {      

    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM