Jump to content

Facebook Graph api - Feed only returns ID


Drongo_III

Recommended Posts

Hi Guys

 

Having my first unsuccessful trip into the world of facebook graph api (oh how i hate facebook).

 

All I want to do is retrieve the facebook wall posts for a specified user.

 

I created an app to get an access token and secret that part appears to be working as no errors are being returned.

 

However when i try to pull the feed using the following line of code I get only the user ID back and nothing else:

 

$json_str = file_get_contents('https://graph.facebook.com/100005065530030?fields=feed&access_token='.$access_token);

 

If I replace ''feed' with 'name' I get the name so it's clearly working on one level.

 

As I am woefully unfamiliar with facebook api I would very much appreciate if someone could give me a clue as to why this might be happening?

 

Thanks,

 

Drongo

Link to comment
Share on other sites

Hi Guys

 

I worked this out in the end and I learned two things - firstly that most tutorials for this online are outdated, and secondly that facebook is the single largest sack of horse s%$t known to man with a 'war and peace' sized documentation that is mostly contradiction and dead ends.

 

Anyway rant aside I thought I would post the solution that will hopefully help other facebook dev. noobies like me work it out.

 

The very first step is to setup an app. For this you need to have a normal facebook profile and not a page account. IF you register just with a page style account facebook will still let you register as a developer, it will still let you enter your telephone number but once you get to the app section it will not give you the 'create app' button that you need - but facebook wont tell you that! And then you'll try to register a normal profile account and it wont let you re-enter that telephone number to register as a dev again - haha yes it's true!

 

One you've visited the dev section of facebook and registered there (you need to enter your telephone number and they text you a code) then click 'create app'. Once you create the app you will get an 'App ID' and 'App Secret' - two long strings. Note those down and then use the script below to access the graph api:

 

// First off you need to get an access token. This is done by sending a HTTP request to facebook. Facebook responds with a $_GET variable named $access_token . You can access this by parsing the $appToken result.

$appToken = file_get_contents('https://graph.facebook.com/oauth/access_token?client_id=APP_ID_GOES_HERE&client_secret=APP_SECRETE_GOES_HERE&grant_type=client_credentials');

// Use this function to retrieve the $_GET var. The variable name, as sent by FB, is called $access_token

parse_str($appToken);

//Now we've retrieved the access token we can make a call to the graph api for user data. In this instance we request id, name, feed. Requesting 'feed' retrieves status updates. It gets returned as Json

$json_str = file_get_contents('https://graph.facebook.com/USER_PAGE_ID_GOES_HERE?fields=id,name,feed&access_token='.$access_token);

//Decobe the json str which gives an array and then go nuts

$data = json_decode($json_str);

//var_dump($data);
//print_r($data);

 

 

Hi Guys

 

Having my first unsuccessful trip into the world of facebook graph api (oh how i hate facebook).

 

All I want to do is retrieve the facebook wall posts for a specified user.

 

I created an app to get an access token and secret that part appears to be working as no errors are being returned.

 

However when i try to pull the feed using the following line of code I get only the user ID back and nothing else:

 

$json_str = file_get_contents('https://graph.facebook.com/100005065530030?fields=feed&access_token='.$access_token);

 

If I replace ''feed' with 'name' I get the name so it's clearly working on one level.

 

As I am woefully unfamiliar with facebook api I would very much appreciate if someone could give me a clue as to why this might be happening?

 

Thanks,

 

Drongo

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.