How can I filter the news feed by type=status, using the Graph API of Facebook's home? - facebook

The Graph API of Facebook's home:
Request:
https://graph.facebook.com/me/home?access_token=.....
JSON response:
{
"data":[
{
"type":"status",
"id":"100003063094116_114168602028576",
"created_time":"2011-11-07T16:28:44+0000"
},
{
"type":"link",
"id":"100003063094116_114172085361561",
"created_time":"2011-11-07T16:27:44+0000"
}
],
"paging":{
"previous":"https://graph.facebook.com/me/home?fields=type&limit=2&access_token=....&since=1320683324",
"next":"https://graph.facebook.com/me/home?fields=type&limit=2&access_token=....&until=1320683263"
}
}
How can I can filter the news feed of "type"="status"?

You may try FQL query instead:
SELECT status_id, time, source, message FROM status WHERE uid = me()
me() may be replaced by any other facebook user ID
and may be tested here

Related

How to check if user is a fan of facebook page by using FQL?

I want to check if user is a fan of a specific facebook page, I have tried many times with FQL but the response is always null:
FB.api({
method: 'fql.query',
query: 'SELECT uid FROM page_fan WHERE uid=user_id AND page_id=page_id'
}, function(resp) {
if (resp.length) {
alert('A fan!')
} else {
alert('Not a fan!');
}
}
);
I've tried with user table is running good:
FB.api(
{
method: 'fql.query',
query: 'SELECT name FROM user WHERE uid=me()'
},
function(response) {
alert('Your name is ' + response[0].name);
}
);
I've just checked in https://developers.facebook.com/docs/reference/fql/page_fan/. It seems that facebook does not support FQL, so what can I do ?
I really appreciate your help.
UPDATE
I've just tried Graph API solution but the result is array null:
FB.api('/100005548217775/likes/329849167104448',function(response) {
if( response.data ) {
if( !isEmpty(response.data) )
alert('You are a fan!');
else
alert('Not a fan!');
} else {
alert('ERROR!');
}
});
If you don't have an v2.0 app, you can't use FQL at all, because it's deprecated. Furthermore, you're using the wrong method parameter, which is also deprecated.
The official endpoint for FQL is
/fql?q={url_encoded_query}
where {url_encoded_query} is the url encoded FQL query.
I'd recommend you skip FQL, and go with the standard Graph API funcitonality (which is future proof):
/{user-id}/likes/{page-id}
Note that you'll need the user_likes permission in the access token to be able to get any result.
See
https://developers.facebook.com/docs/graph-api/common-scenarios#pagelikes
I've found my answer:
FB.login(function(response){
if(response.status=='connected'){
FB.api('/me/likes/' + 216524221773305, function(api_response)
{
if(api_response.data.length > 0){
setLocation('<?php echo $this->getConnectUrl() ?>');
}else{
jQuery('#facebook-like-popup').show();
}
});
}
}, {scope: 'user_likes'});
There is one thing that make me confused that is: When I've just liked a fan page then check the result still return Array[]. It seems that Facebook doesn't update data immediately. Not sure what I think is right ?
This will not either work as you need user_likes permissions from facebook, you can try something else, lets say that the page you want to find out if a user liked is
https://www.facebook.com/pg/Poulamecom-159391200925483/likes/?ref=page_internal
1)visit page
2)view source
3)find "likeStatus" inside source, if its true then user liked page, if false then user did not like the page
4)"visit page" could be done automatically by a script and check if likeStatus":true or likeStatus":false

How do I get the likes number from facebook for a given url?

A url http://www.cnn.com/2014/03/15/world/asia/malaysia-airlines-passenger-vignettes/index.html?hpt=hp_t1
How can I get the facebook like number or twitter posts number or google+ number from this url?
You can use the following FQL via the Graph API:
select url, like_count from link_stat where url='http://edition.cnn.com/2014/03/15/world/asia/malaysia-airlines-passenger-vignettes/index.html'
like this:
https://graph.facebook.com/fql?q=select%20url%2C%20like_count%20from%20link_stat%20where%20url%3D%27http%3A%2F%2Fedition.cnn.com%2F2014%2F03%2F15%2Fworld%2Fasia%2Fmalaysia-airlines-passenger-vignettes%2Findex.html%27
which gives the result
{
"data": [
{
"url": "http://edition.cnn.com/2014/03/15/world/asia/malaysia-airlines-passenger-vignettes/index.html",
"like_count": 28529
}
]
}

FaceBook API for friends count

There is the question about fetching count of user friends via FaceBook API.
I want to get the number of friends only have USER_ID of the any facebook user. As I know I can get it using FQL like:
SELECT friend_count FROM user WHERE uid = X
But for some users this value is null or there is no value. Please advice is there another way to get this value?
That user might be keeping that information private. In that case, you cannot fetch that information.
You just check the following link. You need to generate token (by clicking on Get Token you will get it) with data you want from facebook API, need to select friends option to get the friend count.
https://developers.facebook.com/tools/explorer/?method=GET&path=me%3Ffields%3Did%2Cname%2Cfriends&version=v2.8
FB.api(
'/me',
'GET',
{"fields":"id,name,friends,link,email,gender,picture,first_name,last_name,cover"},
function(response) {
// Insert your code here
}
);
after executing this you will get this in response as
{
"id": "XXXXXXXXXX",
"name": "Test test",
"friends": {
"data": [
],
"summary": {
"total_count": 14
}
}
}
total_count will be your friend count

How To Get User Name From Facebook Unity SDK

I am new in unity and trying to integrate Facebook unity SDK. But i am not able to find current logged-in user name. It will return only userId and accessToken. How to get login name after FB.Login("email")
After you login, you can get the name with:
FB.API("me?fields=name", Facebook.HttpMethod.GET, <your callback here>);
After calling the API
FB.API("me?fields=name", Facebook.HttpMethod.GET, NameCallBack);
get the exact name from the JSON like this:
void NameCallBack(FBResult result)
{
IDictionary dict = Facebook.MiniJSON.Json.Deserialize(result.Text) as IDictionary;
string fbname = dict["name"].ToString();
}
My best guess if I was to look somewhere is to make use of that userId and FQL to query Facebook for the name of the user.
For instance using the Graph API Explorer:
https://developers.facebook.com/tools/explorer
I used the following query:
Select name from user where uid = [userId]
It returned the following JSON string:
{
"data": [
{
"name": "myName"
}
]
}
I think you can use https://developers.facebook.com/docs/php/howto/profilewithfql/ to get an idea of how to query the FB.API to perform a FQL query.
FQL Guide: https://developers.facebook.com/docs/technical-guides/fql/

Fql page liked returns empty array

Im using this query and for some users it returns correct response but for some it returns empty array. I am only changing userId. Is it because of some privacy settings ?
SELECT uid FROM page_fan WHERE page_id = pageId and uid = userId
For some users it returns a good response:
{
"data": [
{
"uid": userId
}
]
}
and for some it returns a bad response like this even if they liked the page:
{
"data": [
]
}
Im using extended permissions read_stream
I updated my permissions with user_likes and uninstalled application and it works just fine.