Facebook API to retrieve wall feed - facebook

I've never done any facebook development and am working on a project which I only require to pull out wall stream from a certain user. Is there such an API I could use for this purpose?

Facebook exposes a generic API. You can write your own methods of accessing it, or you can use Facebook's libraries (if your preferred language is available). Check out the following link to get started:
Getting started

Well, if you're happy with JSON, just using the graph API is a good start.
e.g. https://graph.facebook.com/starbucks/feed
Not too hard to pull that down with Python and put the data in a table...

Though this is an old post, still i am putting in my reply. This might be helpful.
I am using php sdk and here is code for getting the users wall posts (includes posts by other users as well)
$facebook = new Facebook(array(
'appId' => '101874630007036',
'secret' => '2090c8d645ae93e7cacee2217cd3dc0c',
));
$user = $facebook->getUser();
// Login or logout url will be needed depending on current user state.
if ($user)
{
$logoutUrl = $facebook->getLogoutUrl();
}
else
{
$params = array('scope' => 'read_stream');
$loginUrl = $facebook->getLoginUrl($params);
}
if ($user)
{
$comments = $facebook->api('/me/home');
}
here $comments contains the wall post json data.

Related

suddenly facebook connect stopped working

A few days ago the facebook connection with our website stopped working all of the sudden, nothing was changed to the code???
Facebook made some changes???
http://www.presbium.sk/vstup-pre-uchadzacov/
require 'facebook-php-sdk/src/facebook.php';
$facebook = new Facebook(array(
'appId' => 'YOUR_APP_ID',
'secret' => 'YOUR_APP_SECRET',
));
// Get User ID
$user = $facebook->getUser();
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl();
}
enter code here
You can find everything you need there:
http://developers.facebook.com/docs/
For login:
http://developers.facebook.com/docs/authentication/
for Facebook Connect:
http://developers.facebook.com/docs/reference/api/
Facebook Login is not an official Facebook expression. The official term for this is Facebook Authentication. Facebook Connect was the expression used for the server to server technology, back when the Rest API was up to date. Now, you have to use the Graph API to do the same things. You can find the infos about the old Rest API here:
http://developers.facebook.com/docs/reference/rest/
But consider these APIs are deprecated and using them for a new development is probably not a good idea.
There are changes to Facebook's API implemented continuously. Some of them may break your app's functionality. A good way to stay-up-to-date about what changes are happening is to following the Operation Developer Love platform updates. There you can find out about bugs and breaking changes to the API. Go through the latest blog updates to see if there is a change you have missed to implement.
Edit:
You wrote:
I did everything as here github.com/facebook/facebook-php-sdk and befor 1 month it works but now it donĀ“t working
The SDK github examples give you a blue print for a general case. The error is most likely something that's app specific, for example which permissions you ask for. I recommend you really go through all the 'breaking changes' in the blog for the past 3 months and see what it can be. For example, the 'offline access' permission was removed a while ago. If your app still asks for it, the apps expected behaviour may break. There are also new requirements for having a privacy policy that if not met may cut off the app's access to parts of the API. I'm not saying these are the source of issue with your app, they're just examples. Real examples.

how to tell if the user is already logged in and has already accepted my app

I am just creating a facebook tab on a users page.
I am using the php facebook SDK, and this little snippet(see below) from the tutorials.
My question is , if the user is logged into FB and comes back to my page later $user is not found and they have to connect again. Is there not a way to know that they are already logged in and already granted me access?
I hope this question makes sense
$facebook = new Facebook(array(
'appId' => FB_APP_ID,
'secret' => FB_APP_SECRET,
'cookies' => 'true'
));
$user = $facebook->getUser();
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl(array('scope' => 'publish_stream, manage_pages'));
}
Nope, it won't be done automagically on server-side. To know who user is - you need to ask them to follow the login url
OR
use JS SDK. In that case user is logged in automatically and all you need is to refresh the page by JS (there is an example shipped with php sdk on how to do that)

Upload to specific Fan Page Album without user perms

I'm trying to replicate the same functionality as someone else has already achieved on this page here:
http://www.facebook.com/PowerPhotoUploader?sk=app_152884604799537
am not bothered about the forced like fangate part, can do that no probs.
I need to achieve this without requesting any user perms the same way they have
I've got close, but not quite right yet.
Have created a test album on this page: http://www.facebook.com/pages/Demo-Album-Upload/227979503931257?sk=app_153866511376478
The code I have is uploading my specified image, however it is ignoring the album id I input and instead, uploading to an album on my own profile.
Code so far is:
<?php
$app_id = "XXXXXXXXXXX";
$app_secret = "XXXXXXXXXXXX";
require 'facebook.php';
$facebook = new Facebook(array( 'appId' => $app_id, 'secret' => $app_secret, 'cookie' => true, 'fileUpload' => true,));
$signed_request = $facebook->getSignedRequest();
//print_r ($signed_request);
$page_id = $signed_request["page"]["id"];
//Upload To Page Album
$facebook->setFileUploadSupport(true);
$album_id ='59125';
$file_path ='image2.gif';
$args = array('message' => 'Photo Caption');
$args['image'] = '#' . realpath($file_path);
$data = $facebook->api('/'.$album_id.'/photos', 'post', $args);
print_r($data);
?>
Have already read through a lot of forum material, have set the filuploadsupport, set file upload to true, but most of the info I can find so far reuires perms & access token, however sample above has managed to achieve with neither - any thoughts?
Regards Tony
Tony the trick here is that you only need one access token, not a new one for each user. The idea is that the user is not posting to the page, you are posting to the page, so you do not need an access token from the user. However since this is a secure call to Facebook you still need to provide an access token that has the ability to publish to the page.
The simplest route to get an access token that you can use would be to manually give the application the manage_pages and offline_access permissions for your account. Then just grab the access token for for your account and use it for all calls.

$facebook->getUser() always returns 0 [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Why is Facebook PHP SDK getUser always returning 0?
Am using the following code to authenticate Facebook uses and redirecting them to login page if not logged in or require permission. Problem is getUser() always returns 0 causing the code to get stuck in a redirecting loop. Any ideas?
include_once("facebook.php");
$app_id = 'xxxxxxxxxxxx';
$app_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
// initialize facebook
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
));
$user = $facebook->getUser();
echo $user;
if ($user) {
try {
$fbme = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
else
{
$loginUrl = $facebook->getLoginUrl(array('scope' => 'email'));
header('Location: '.$loginUrl);
}
After days of searching I found that I just wasn't adding a 'code' key value when using the Facebook API. The system needs it in order to validate
When you use the API function $facebook->getLoginUrl(); it takes you to a login-page that (when you authenticate properly) simply returns you to your own website with a code="x" parameter in the navigation bar. So when instantiating the Facebook Object you simply use a get request to nab this piece of information.
when your page reloads the Facebook API, make sure that one of its key values is
'code' => $_GET['code'],
sorted..
Really angry that I had to figure this out myself.. Look at the getLoginUrl() docs here http://developers.facebook.com/docs/reference/php/facebook-getLoginUrl/ and you'll find that nowhere does it specify what it returns, just that it "authorises" the app, whatever the hell that means.
Also on the main page of the PHP API docs found here http://developers.facebook.com/docs/reference/php/, it states that the minimum number of parameters required are an app secret and an appID. If this is the case, then why does adding the code sort my problem?
If I'm talking nonsense, please respond. I like to know the error of my ways :).
This is not a sdk related problem, SDK (3.1) working well. getUser() and PHP-SDK silently fails if _REQUEST like globals dropping by http server if misconfigured. I was using wrong-configured nginx and after tracing code ~3 hours solved this problem via vhost configuration change.

Facebook Graph API getAccessToken() not working

I have been working on the Graph API for the past few days. When I try to make an API call using the PHP-SDK, i get an empty json object as a response. But when i copy the access token from the links that are provided by FB in http://developers.facebook.com/docs/reference/api/, i get a json response.
I assume that this is because of the Access Token that i am sending in the request.
Help Appreciated.
My Code :
include_once "fbInit.php";
$access = $facebook->getAccessToken();
$user = $facebook->getUser();
echo $access;
if(!$user)
{
$loginUrl = $facebook->getLoginUrl();
header("Location:".$loginUrl);
}
$userWall = $facebook->api('/me/feed',array('access_token'=>$access)) ;
var_dump($userWall);
getAccessToken() only returns the internally stored access token in the SDK, it doesn't generate or fetch one. One advantage of using the SDK is that you don't need to pass in the access token directly like you're doing toward the end of your example. Once the user clicks the link generated by getLoginUrl(), the access token will automatically be stored in the SDK and the api method will work. Posting to a user's wall requires more parameters than you're passing in, however. You can see a complete example of how to do this in the recently-released PHP SDK docs at https://developers.intern.facebook.com/docs/reference/php/facebook-api/
This works for me:
index.php
<?php
require_once("./config.php");
$me = $facebook->api('/me');
$access_token = $facebook->getAccessToken();
$user = $facebook->getUser();
$userWall = $facebook->api('/me/feed',array('access_token'=>$access_token));
var_dump($userWall);
?>
config.php
<?php
require_once("facebook.php");
$app_id = "app_id";
$app_secret = "app_secret";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
if(is_null($facebook->getUser()))
{
header("Location:{$facebook->getLoginUrl(array('req_perms' => 'user_status,publish_stream,user_photos'))}");
exit;
}
?>
The api suppose to fetch the access token for you - it form a access_token graph api at base_facebook.php line 664. Unfortunately this api call maybe failed due to your redirect uri - some had mentioned that you should not have a "?" in your redirect uri and in my case - there is a tail "/", which caused this call failed. And same redirect uri had no problem if you direct call through "https://graph.facebook.com/oauth/access_token?".
Try to put a log to print out the response result from facebook in _graph() function within base_facebook.php will help you quickly determine whether you are hit by same problem as me.