0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Get all comments of facebook post by weird way.

Posted at

Graph API Explorer is a facebook developer tool, and I usually use it recently.

One day, a problem about the large amount of post comments occurred.

1.png

It's hard for me to read, I need to keep click 'more' button.

So, why can't I solve this prolbem with Graph API Explorer?

Here's the way.

Get ID

Everything from fb has its own id. (post, video, photo, etc)

The most URL format like these below:

  • facebook.com/groups/[group_name]/permalink/[id]
  • facebook.com/photo.php?fbid=[id]
  • facebook.com/[username]/posts/[id]
  • facebook.com/permalink.php?story_fbid=[id]

Remeber the id we found, we'll use it later.

Query data

Then we open the Graph API Explorer, switch to FQL Query mode to get the comment data by FQL.

SELECT fromid, text FROM comment WHERE object_id = '[id]' LIMIT 0, 500

You might have a question that why I select fromid not name. (if I can, I want to.)

Becuz there's no name column in comment table, and fb not allow us to join table in this tool.

But I still found the solution, I'll mention it later.

Now the comment data will shown in JSON format.

Make it easy

We already know these steps will get the comment data.

But how to make it easier is more difficult.

Here I use js bookmark to do these step by step.

var obj_id;
var step;
if (step == undefined) { //Get the id from user
    obj_id = prompt('Enter the id:');
    if (obj_id != undefined) {
        step = 'enter_Id';
    }
    return false;
} else if (step == 'enter_Id') { //Set FQL to query data.
    document.getElementById('fql_query').value = "SELECT fromid, text FROM comment WHERE object_id = '" + obj_id + "' limit 0, 500";
    document.getElementById('fql_submit').childNodes[0].click();
    step = 'query_text';
    alert('Wait until the loading complete, and click this bookmark again.');
} else if (step == 'query_text') { //Select all data
    var content = document.getElementById('response_body');
    var selection = window.getSelection();
    var range = document.createRange();
    range.selectNodeContents(content);
    selection.removeAllRanges();
    selection.addRange(range);
    content.focus();
    alert('Press ctrl+c to copy.');
}

why fromid not name

Back to the fromid problem before, fromid means the id of the user who create comment.

Each comments has its own fromid and text, so I use async to get the name of user profile from 'http://graph.facebook.com/[fromid]' in order.

But the sad part is I found it's still hard for end user to operate.

Look on the bright side, I found a tricky method to use this tool.

Hope these help. :)

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?