Facebook graph api returns empty result - facebook

I am trying to pull user feeds from facebook, But the array of result i am getting is empty. The code i am using is
$jsonurl = "https://graph.facebook.com/{$user_id}/feed?limit=25&access_token={$access_token}";
$json = file_get_contents($jsonurl,0,null,null);
$user_data = json_decode($json, true);
print_r($user_data);
The result always getting is
Array ( [data] => Array ( ) )
Can anyone help me to find what the issue is?
Thanks in advance

I have tried your give code in my php code.
It is working find. Please check that the USERID which you are posting has a feed.
To test try BMW, FACEBOOK userid so you can find the feeds.
Try below url you will get its feed.
https://graph.facebook.com/BMW/feed?limit=25&access_token={$access_token}

Related

Soundcloud API get only permalink_url

How can I get the permalink_url only of using Soundcloud API tracks?
It returns all fields.
How am I able to return only the permalink_url?
I tried this but no luck: I tried this but no luck: http://api.soundcloud.com/tracks.json?client_id=XX&q=Charlie%20Puth&limit=100&fields=permalink_url
You should be able to parse the returned JSON for the permalink_url. Something like:
var parsedJSON = JSON.parse(tracksJSON);
var permalink = parsedJSON.permalink_url;
If you have jQuery, I believe $.getJSON automatically parses the info for you as well. I hope this helps you!

How to fetch Facebook profile picture & name w/o app?

Does anyone have any idea how to fetch profile picture and first + last name of Facebook member by his profile link/ID without authorising app or anything.
You can retrieve that data from following URL:-
https://graph.facebook.com/USERNAMEORID?fields=id,name,first_name,last_name,picture
Replace "USERNAMEORID" to fb username or id of specified user.
You can fetch these data as following:-
<?php
$content = file_get_contents('https://graph.facebook.com/myid?fields=id,name,first_name,last_name,picture');
$content = json_decode($content, true);
print_r($content); // <- this print data as associative array, You can fetch it and get data
?>
I added a json_decode function to your code whereas the data coming form facebook graph is json format, So i used that function to convert json format to object, Then i used true parameter to make this object as associative array. Now you can fetch this array normally as any array.
If you need anything else tell me, I'll be happy to help.

Getting list of friends with koala and fb api

Im trying to return the friend list with uid of an authenticated user. however I only get a partial return value, some part of the friends are just left out:
graph = Koala::Facebook::API.new(fb_token)
friends = graph.get_connections("me", "friends")
#some friend action
when I type in the
friends.paging["next"]
in the browser it also returns an empty json array
"data": [ ]
How am I doing it wrong and what is the correct practice?
You need to get the permission 'user_friends' to get friendlist, otherwise you'll receive a empty data:
The field 'friends' is only accessible on the User object after the user grants the 'user_friends' permission.
Try yourself:
https://developers.facebook.com/tools/explorer?method=GET&path=me%2Ffriends&version=v2.5
So, with correct permission you can do:
graph = Koala::Facebook::API.new(fb_token)
result = graph.get_connections('me', 'friends')
to paginate:
next_page = result.next_page
LAST BUT NOT LEAST:
Only friends who installed this app are returned in API v2.0 and
higher. total_count in summary represents the total number of friends,
including those who haven't installed the app.Learn More
You just try this..
This is very simple to you can get all friend count in a single line :)
#graph = Koala::Facebook::API.new(facebook_token)
#friends = #graph.get_connection("me", "friends",api_version:"v2.0").raw_response["summary"]["total_count"]

Facebook SDK API: How to get details on post shares?

I'm using the FB PHP SDK to get info on a post in a page I manage.
So far I can get:
$result = $facebook->api("/123xx");
$result = $facebook->api("/123xx/likes");
$result = $facebook->api("/123xx/comments");
$result = $facebook->api("/123xx/insights");
This gives me a lot of info, but I'm missing details about 'shares'. All I get is
[shares] => Array
(
[count] => 13
)
but no user ids or comments associated with those shares. Is there a way to pull that info with the SDK (or FQL)?
Regarding permissions, my script is asking for 'scope' => 'manage_pages,read_insights' Do I need another param to request this info?
Thanks for any assistance

Are data acquired from Facebook GRAPH API real-time?

I am creating a Facebook application that will download all the photos in an album. The application is created for my personal use and at the same time, learn the Facebook API and JSON.
I can already retrieve the URL of the photos inside an album by calling this url:
http://graph.facebook.com/[album id]/photos?fields=source
The album that I'm trying to download contains 5400+ photos so I tried increasing the limit by adding the limit parameter:
http://graph.facebook.com/[album id]/photos?fields=source&limit=1000
Here's the problem:
The results being returned are only until 2010-07-30T11:20:11+0000. When I tried to modify the query by using the until parameter like so:
http://graph.facebook.com/[album id]/photos?fields=source,link&limit=1000&until=2010-06-01
the data responded correctly. However, if I changed the date to something like 2010-08-05, the latest photo returned will have a created_date of 2010-07-30T11:20:11+0000.
The last photo returned is photo #5000 out of 5695.
Here's my question:
Is the data acquired from Facebook GRAPH Api real-time (or a Monthly update, 2010-07-30)? Or there's just a limit on the number of photos returned on album (like 5000)?
Thanks!
EDIT
There is a 5000 object limit in Facebook. If you know how to break the limit, go here:
Breaking the 5000 object limit in Facebook API
Thanks!
There is indeed 5000 limit on returned objects. You would need to run multiple FQL queries on photo table ordering and limiting the results (<5000) to get all the data (check photo table page for examples). (doesn't work)
When I look at the photos in the graph query you linked
https://graph.facebook.com/119403264763178/photos
I see paging information at the bottom. So, hacking together a quick test
$request = 'http://graph.facebook.com/119403264763178/photos?fields=source&limit=1000';
$response = json_decode( file_get_contents( $request ), true );
$totalCount = 0;
while ( count( $response['data'] ) )
{
echo 'Fetching ' . urldecode( $response['paging']['next'] ) . '<br>';
$totalCount += count( $response['data'] );
$response = json_decode( file_get_contents( $response['paging']['next'] ), true );
}
echo $totalCount;
It would seem that even following the paging data, you can still only retrieve 5000 records.
I'd suggest hitting up the FB forums or opening a bug ticket.