0

I have made a chrome extension for facebook, for private liking. What I want to do is, whenever someone posted a post, and a person clicked the private like button, which has been included by me. On click of this private like button, i want to get the JSON data of the poster who posted the post. For now i just tried to get JSON of my own profile, but It does not return anything. Below is the code !

var btn = "<button class=\"nadddim\" >Get JSON</button>";
var t = document.getElementsByClassName("_sg1 _3qd4");
t[0].insertAdjacentHTML('beforebegin', btn);



document.getElementsByClassName('nadddim')[0].addEventListener('click',function(){

var fbjson;

$.getJSON( "https://www.facebook.com/profile.php?id=100004774025067", function( data ) {
  fbjson = data;
});

console.log(fbjson);
});

Basically need the user id , from his post, for example John posted something, whenever I privately liked that post, I want to get the JSON of John to extract his id value ! Thats All I need

Antesoft
  • 61
  • 1
  • 10

1 Answers1

0

You need to use the method .done() to get the return data since the getJSON call is asynchronous like this:

$.getJSON( "https://www.facebook.com/profile.php?id=100004774025067" ).
        .done(function( data ) {
            fbjson = data;
        })
        .fail(function() {
            console.log( "error" );
        })

Also, you might want to check if there's any errors using fail() , see http://api.jquery.com/jquery.getjson/. To view the content of the error examine the jqXHR object (jQuery XMLHttpRequest) for instance like this:

        .fail(function(jqxhr){
            console.log( "error" );
            console.log(jqxhr.responseText);
         })
user2314737
  • 27,088
  • 20
  • 102
  • 114