Get Friends List in facebook Graph Api? - php

yesterday i got answer get friends list from facebook using App_id and App_secret i got friends list.today i trying to run the code i getting error.but same code working yesterday ?
today I am getting Error Like this
Fatal error: Call to undefined method Facebook::getLoginStatusUrl() in D:\xampp\htdocs\kenshinkan-new\kenshinkan\facebook.php on line 34
<?php
require '/src/facebook.php';
$facebook = new Facebook(array(
'appId' => 'xxxxxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxx',
));
$app_id = 'xxxxxxxxxxxxxxxxxxxx';
$app_secret = 'xxxxxxxxxxxxxxxxxxx';
$user = $facebook->getUser();
if ($user) {
try {
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
$result = $facebook->api('/me/friends');
print "<pre>";
// print_r($result);
$json_output=($result['summary']['total_count']);
echo "$json_output";
print "</pre>";
} else {
$statusUrl = $facebook->getLoginStatusUrl();
$loginUrl = $facebook->getLoginUrl(array('scope' => 'user_friends,read_stream, export_stream'));
}
?>
<!doctype html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<title>demo</title>
</head>
<body>
<?php if ($user): ?>
<h3>You</h3>
<img src="https://graph.facebook.com/<?php echo $user; ?>/picture">
Logout
<?php else: ?>
<div>
Login:Login with Facebook
</div>
<?php endif ?>
</body>
</html>
but this code working yesterday? Today i am getting Error? how to solve this error? i want get friends list from facebook? please any idea about it?

I got Answer. i have just change Line
$statusUrl = $facebook->getLoginStatusUrl();
change To
$statusUrl = $facebook->getLoginUrl();
its Working Good Now...

Related

Extracting friend's list using Facebook PHP SDK

I am stuck with this issue since awhile now. I am trying to retrieve my friends list (who are using this app, ofcourse). The SDK version is 3.2.3. The code does pull out information from my profile, but does not pull anything from my friends profiles. Though i am using the scope permission parameter with my login. Following is my index.php file :
require_once('facebook.php');
$config = array(
'appId' => 'xxxx',
'secret' => 'xxxx'
//'allowSignedRequest' => false
);
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
<html>
<head></head>
<body>
if($user_id) {
try {
$user_profile = $facebook->api('/me','GET');
echo "<pre>";
print_r($user_profile); //prints my profile
echo "</pre>";
foreach ($user_profile["data"] as $friend) {
echo $friend['id'];
echo $friend['name'];
}
echo '<br><a href=' . $facebook->destroySession() . '>Logout</a>';
} catch(FacebookApiException $e) {
}
} else {
$params = array(
'scope' => 'public_profile, user_friends, email',
);
$login_url = $facebook->getLoginUrl($params);
echo 'Please login.';
}
</body>
</html>
How can i just print my friend's list? (those friends whose permission i have!)
Change the
$user_profile = $facebook->api('/me','GET');
to
$user_profile = $facebook->api('/me?fields=id,first_name,last_name,friends','GET');
for example.

facebook php sdk not working

i used two codes and its not working the first one :
<?php
require_once('fb/facebook.php');
$config = array(
'appId' => 'xxxxx',
'secret' => 'xxxxx',
);
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
?>
<html>
<head></head>
<body>
<?php
function render_login($facebook) {
$canvas_page = 'http://fbbost.eb2a.com/';
// HERE YOU ASK THE USER TO ACCEPT YOUR APP AND SPECIFY THE PERMISSIONS NEEDED BY
$login_url = $facebook->getLoginUrl(array('scope'=>'email,user_photos,friends_photos', 'redirect_uri'=>$canvas_page));
echo 'Please login.';
}
if($user_id) {
try {
$user_profile = $facebook->api('/me','GET');
echo "Name: " . $user_profile['name'];
} catch(FacebookApiException $e) {
render_login($facebook);
echo "1";
error_log($e->getType());
error_log($e->getMessage());
}
} else {
render_login($facebook);
echo "2";
}
?>
</body>
</html>
and the second one :
<html>
<head>
<title>NNN</title>
</head>
<body>
<?php
include "fb/facebook.php";
$facebook=new Facebook(array(
'appId' => 'xxxxx',
'secret' => 'xxxxx',
'cookie' => true
));
$session=$facebook->getUser();
$me=null;
if($session){
try{
$me=$facbook->api('/me');
print_r($me);
}
catch (FacebookApiException $e){
echo $e->getMessage();
}
}
if($me){
$logoutUrl=$facbook->getLogoutUrl();
echo "<a href='$logoutUrl'>Logout</a>";
}
else{
$loginUrl=$facebook->getLoginUrl(array(
'scope' => 'publish_stream,read_friendlists'
));
echo "<a href='$loginUrl'>Login</a>";
}
?>
</body>
</html>
both codes return the same error when i login :
App Not Setup: The developers of this app have not set up this app properly for Facebook Login.
I think your app is not public. You need to set it to public to use it with any Facebook account other than the developer's own account. Go to "Status and Review" and make the app public.
Besides, check that you have properly setup the app domain.

I am using php sdk to post on facebook but the page is not loading

I am using the following code to post on facebook from my page but the lonin page is not loading
you can see the page
When I click on the following link the facebook required page is not loading
The code is look like that
<?php
require 'src/facebook.php';
$facebook = new Facebook(array(
'appId' => '198516340340394',
'secret' => 'f11117b96e0996ecbf7d7f4919c0cf70',
'cookie' => true
));
$user = $facebook->getUser();
$user_profile = null;
if ($user) {
try {
$user_profile = $facebook->api('/me');
$facebook->api('/me/feed/', 'post', array(
'message' => 'I want to display this message on my wall'
));
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
if ($user_profile) {
$logoutUrl = $facebook->getLogoutUrl();
echo 'Logout';
} else {
$loginUrl = $facebook->getLoginUrl(array(
'scope' => 'publish_stream, read_friendlists',
));
echo 'Login';
}
?>
<html>
<head>
<title>PHP SDK</title>
</head>
<body>
</body>
</html>
Please help me in this case and please give me the detail answer, and be with me
There are a couple problems with what you're doing here.
First it's always best to have valid markup ie doctype and html tags your page is missing. but more importantly... this
echo 'Login';
is wrong. the markup is just as it looks I think you're expecting a link. Change it to
echo 'Login;
and try again. the reason is php does not recognize variables in a single quoted string.

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>

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