Facebook api not returning Comments - php

im trying to get some data with the facebook api. Here is my code
<?php
include 'src/facebook.php';
$facebook = new Facebook(array(
'appId' => 'xxx',
'secret' => 'xxx',
'cookie' => true
));
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<?php
$user = $facebook->getUser();
if($user)
{
$user_profile = $facebook->api('/me/statuses');
echo "<pre>", print_r($user_profile), "</pre>";
echo "<a href=logout.php>Logout</a>";
}
else
{
$login_url_params = array(
'scope' => 'publish_stream,read_stream,offline_access,manage_pages'
);
$login_url = $facebook->getLoginUrl($login_url_params);
//redirect to the login URL on facebook
header("Location: {$login_url}");
}
?>
</body>
</html>
The problem is that when i print_r($user_profile) it shows all the data that is supposed to come with $user_profile = $facebook->api('/me/statuses'); but it doesn't show the comments associated with the status. I tried this in the Graph API Explorer and it works fine (shows all of the data), but in my code when i run it; it doesn't get the comments.
Any idea on why this is happening?

$user_profile = $facebook->api('/me/feed');

Related

Facebook app fails to get users credentials

I am new to programming and I want to develop a Facebook app with the PHP SDK. I'm hosting the app on heroku and I want to get the users login credentials with the following code.
<?php
require 'php-sdk/facebook.php';
$facebook = new Facebook (array(
'appId' => 'appId',
'secret' => 'appsecret'
));
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>Facebook PHP </title>
</head>
<body>
<?php
$user = $facebook -> getUser();
if($user)
echo 'User ID:' , $user , '</p>';
else:
$logoutUrl = $facebook->getLogoutUrl();
echo '<p>login</p>';
endif;
?>
However I get 500 (Internal Server Error) on 'CanvasIFrameLoader' line. Am I missing something?
d('CanvasIFrameLoader',['XdArbiterBuffer','Banzai','$'],(function a(b,c,d,e,f,g){c('XdArbiterBuffer');var h={loadFromForm:function j(k,l,m){var n=c('$')('iframe_canvas');if(l&&!i()){l.style.display='block';n.style.display='none';return;}var o=Date.now();n.onload=function(){var p=Date.now(),q=p-o;c('Banzai').post('canvas_iframe_load',{app_id:m,iframe_time_to_load:q});};k.submit();}};function i(){try{var j=document.createElement('canvas');return Boolean(window.WebGLRenderingContext)&&Boolean(j.getContext('webgl')||j.getContext('experimental-webgl'));}catch(k){return false;}}f.exports=h;}),null);
Thank you!

hi every one i'm just getting this error:failed to connect to 255.255.255.255: network is unreachable

I’m just using facebook php sdk v3.2.3
error type : curl exception…
I just use host with curl but it doesnt work…
Here is my code:
<?php
require 'facebook.php';
$facebook = new Facebook(array(
'appId' => '',
'secret' => ''
));
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Facebook PHP</title>
</hea <body>
<h1>Hello World</h1>
<?php
//get user from facebook object
$user = $facebook->getUser();
if ($user): //check for existing user id
try {
$user_profile = $facebook->api('/me','GET');
echo "Name: " . $user_profile['name'];
} catch(FacebookApiException $e) {
// If the user is logged out, you can have a
// user ID even though the access token is invalid.
// In this case, we'll get an exception, so we'll
// just ask the user to login again here.
$login_url = $facebook->getLoginUrl();
echo 'Please login.';
echo '<p>getType: ',$e->getType(), '</p>';;
echo '<p>getMessage: ',$e->getMessage(), '</p>';;
}
echo '<p>User ID: ', $user, '</p>';
//print logout link
echo '<p>logout</p>';
else: //user doesn't exist
$loginUrl = $facebook->getLoginUrl(array(
'diplay'=>'popup',
'scope'=>'email',
'redirect_uri' => 'http://apps.facebook.com/blabla'
));
echo '<p>login</p>';
endif; //check for user id
?>
</body>
</html>
Just a few modifications will solve it, I GUESS (Guess, as I don't still see the facebook.php)
<?php
require 'facebook.php';
$facebook = new Facebook(array('appId' => '', 'secret' => ''));
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Facebook PHP</title>
</head>
<body>
<h1>Hello World</h1>
<?php
//get user from facebook object
$user = $facebook->getUser();
if ($user): //check for existing user id
try {
$user_profile = $facebook->api('/me','GET');
echo "Name: " . $user_profile['name'];
} catch(FacebookApiException $e) {
// If the user is logged out, you can have a
// user ID even though the access token is invalid.
// In this case, we'll get an exception, so we'll
// just ask the user to login again here.
$login_url = $facebook->getLoginUrl();
echo 'Please login.';
echo '<p>getType: ',$e->getType(), '</p>';;
echo '<p>getMessage: ',$e->getMessage(), '</p>';;
}
echo '<p>User ID: ', $user, '</p>';
//print logout link
echo '<p>logout</p>';
else: //user doesn't exist
$loginUrl = $facebook->getLoginUrl(array(
'diplay'=>'popup',
'scope'=>'email',
'redirect_uri' => 'http://apps.facebook.com/blabla'
));
echo '<p>login</p>';
endif; //check for user id
?>
</body>
</html>
Let's see what will happen, we are tuned here, keep in touch.

Authentification via Facebook need two clicks in some cases

I'm trying to do login via FB. If I'm not logged in FB, everything works fine but if I'm logged in FB and I click on "login via facebook!" hyperlink the URL has changed on comething like this fb2.php?code=AQAlKrGXWS2bhiZ-ZK7UPiDRLdVMjR84jAbxS41kW3I5h5P... but I'm not logged and if I'm not login till I click second time. It's strange, isn't it? Could you someone help me? The source code is here.
<?php session_start();
define('APP_ID', 'my_api_id');
define('APP_SECRET', 'my_app_secret');
define('CANVAS_PAGE', 'http://apps.facebook.com/xxx/');
define('CANVAS_URL', 'http://localhost/xxx/');
require_once 'facebook.php';
$facebook = new Facebook( array('appId' => APP_ID, 'secret' => APP_SECRET, ));
$user = $facebook->getUser();
if(isset($user)) {
try {
xtended_permission)
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
$user = NULL;
}
}
if ($user) { $logoutUrl = $facebook->getLogoutUrl(array('next' =>
"http://metalradio.cz/metalRadioTesting/facebook-sdk/logout.php")); }
else { $loginUrl = $facebook->getLoginUrl( array(
'scope' => 'email' ) ); }
?>
<!doctype html>
<html>
<head>
<title>Facebook login</title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body>
<?php
if(!is_null($user))
echo "Name: " . $user_profile['email'];
?>
<h2>Users authentification via FB</h2>
<?php if ($user):
?>
logout!
<?php else:?>
<div>
login via facebook!
</div>
<?php endif?>
</body>
</html>

Logging into Facebook App redirects to canvas URL

So I've started learning facebook application and got my first obstacle. Whenever i log into my simple hello user application, i'm redirected into canvas URL (App content opens on server directly, instead inside facebook iFrame).
Here's the code
<?php
require_once("php-sdk/facebook.php");
$config = array(
'appId' => '',
'secret' => ''
);
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
$params = array(
'scope' => 'read_stream, friends_likes',
'redirect_uri' => 'https://apps.facebook.com/401822713222945/'
);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<?php
if ($user_id){
try {
$user_profile = $facebook->api('/me','GET');
echo 'Welcome ' . $user_profile['name'] . '!';
} catch(FacebookApiException $e) {
$login_url = $facebook->getLoginUrl();
echo 'Please log in.';
error_log($e->getType());
error_log($e->getMessage());
}
} else {
$login_url = $facebook->getLoginUrl();
echo 'Please log in.';
}
?>
</body>
</html>
Try the following right after the <body> tag.
<script type="text/javascript">
if(top === self){
document.location = "<?php echo $params['redirect_uri'];?>";
}
</script>
It will check if the current window is the most top window, if you're accessing the page directly it will then redirect you to the iframed page.

facebook user authentication and post on user wall

I followed this video tutorial but i am stuck.When i click on the login link the browser keeps loading and then nothing happens and still the login page is in front of me.It always return 0 in $user_id.It showed me the facebook authentication page 1 to 2 times previously and i clicked 'allow' but now nothing is happening.One more thing , when i click the login link the browser url changes from
"http://localhost/php/fbdata.php"
to
"http://localhost/php/fbdata.php?state=e1d5ccf919c6a9d3325200596c12b447&code=AQDg8hE1GuKQ6eq9nGeLV8BIK8EjeIuY8Drf6g0FwAWAjGkvFi70EoNquPmoYsk2PxKpcfxVWYqNgVxU7rRQ-xBxcZXziH5n9IXNNl1KKzLtUYgVRKqWRczh2wINcvDY8WuWoMpIETxWpYhIbrZ-w46xB1v2YMADbOfrFNxLhiyIC239GIQRC__Tw_KiYoZiK1A#="
i dont have any idea if it's returning me something or anything else.
What i want is that i am able to post "hello world" at my facebook page.Here's my php code.
require_once('facebook.php');
$config = array(
'appId' => 'xxxxx',
'secret' => 'xxxxxxxxxx',
'cookie' => 'true'
);
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
$user_profile=null;
if($user_id)
{
try
{
$user_profile = $facebook->api('/me');
$facebook->api('/me/feed','post',array(
'message'=>'hello world'
));
}
catch(FacebookApiException $e)
{
echo $e->getMessage();
}
}
if($user_id)
{
$logout_url=$facebook->getLogoutUrl();
echo "<a href='$logout_url'>Logout</a>";
}
else
{
$login_url=$facebook->getLoginUrl(array(
'scope'=>'read_friendlists,publish_stream,email,user_work_history,user_website,user_religion_politics,user_relationship_details,user_relationships,user_interests,user_hometown,user_education_history,user_birthday,user_about_me'
));
echo "<a href='$login_url'>Login</a>";
}
Mauzzam,
This code works for me - please take a look at the examples folder in the PHP SDK
<?php
require '../src/facebook.php';
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
'appId' => '350881691595504',
'secret' => 'a50ae255f0ba3c24000e38ede7f666b9',
));
$user = $facebook->getUser();
if ($user) {
try {
$response = $facebook->api('/me/feed','post',array(
'message'=>'hello world'
));
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
// Login or logout url will be needed depending on current user state.
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl();
}
?>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<title>PHP SDK TEST</title>
</head>
<body>
<?php if ($user): ?>
Logout
<?php else: ?>
<div>
Login using OAuth 2.0 handled by the PHP SDK:
Login with Facebook
</div>
<?php endif ?>
<?php if ($user): ?>
<h3>Hello World Result</h3>
<pre><?php print_r($response); ?></pre>
<?php else: ?>
<strong><em>You are not Connected.</em></strong>
<?php endif ?>
</body>
</html>

Categories