Facebook FQL comment username = anonymous user

2019-08-29 07:58发布

问题:

When quering the FQL comment table like this:

SELECT post_fbid, fromid, username, time, text FROM comment WHERE post_id = id

I am getting the results but username for every comment is "Anonymous User". Does anyone know why this is happening and has a solution maybe?

Thanks

回答1:

username The user name that a user entered when they posted a comment. In these cases, the fromid returned will be 0. Note that user names for valid users are not returned here.

I honestly don't understand what this username exactly represents but you can simply ignore it!

The fromid gives the ID of the commenter. From that, there is no problem for you to get the user name!

The ID can either be the one of a user or a page. I made a multiquery for you that gathers all the information you need:

{
"comments": "SELECT post_fbid, fromid, time, text FROM comment WHERE post_id=\"205861559433343_336511733034991\"", 
"users": "SELECT uid, username FROM user WHERE uid IN (SELECT fromid FROM #comments)",
"pages": "SELECT page_id, name FROM page WHERE page_id IN (SELECT fromid FROM #comments)"
}


回答2:

The username field only contains data if you are using the Facebook Comments plugin on an external site. People may leave comments without being logged into Facebook. This field reflects data that the user entered when they left the comment.

Otherwise, as Stephane mentions, you need to use the fromid field and resolve this to the actual user.

I would query the profile table to get this, as it returns the owner of any ID, whether it be a page, group or user:

{
"comments": "SELECT post_fbid, fromid, time, text FROM comment WHERE post_id=\"205861559433343_336511733034991\"", 
"commenters": "SELECT id, username, name FROM profile WHERE id IN (SELECT fromid FROM #comments)"
}