I use the following code to connect to the facebook via my site, but the facebook page is not loading.
The cook is 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>
and when I click on the login
If you click on that login here it does not load the facebook
what should I do in this case
You're outputting logoutUrl rather than loginUrl
Change:
echo 'Login';
to use
echo 'Login';
Related
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.
This code always runs the last else part and redirects to the login URL provided by facebook api. If i print the $user variable, it just shows 0 everytime.
$facebook = new Facebook(array(
'appId' => 'app id',
'secret' => 'app secret',
));
$user = $facebook->getUser();
$loginUrl = $facebook->getLoginUrl();
if ($user) {
try {
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
$_SESSION['logouturl'] = $logoutUrl;
$_SESSION['user'] = $user_profile['name'];
$_SESSION['id'] = $user_profile['id'];
$_SESSION['type'] = 'facebook';
header('Location: index.php');
} else
{
$loginUrl = $facebook->getLoginUrl();
header('Location: '.$loginUrl);
}
?>
$facebook = new Facebook(array(
'appId' => 'xx',
'secret' => 'xx',
'scope' => 'read_stream, email'
));
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$params = array(
'scope' => 'read_stream, email'
);
$loginUrl = $facebook->getLoginUrl($params);
make sure your app setting on Facebook is good, rest is looking fine and if you have minor problem in you app setting on Facebook developer console it wont work specially domain name and domain url settings
I am trying to get an access token using the latest Facebook SDK for PHP. To my knowledge I am doing everything correct, but when it redirects to facebook.com/oauth/dialog, it just has a white screen. My code:
<div class="authorize_btn" style="float:right; margin-top:-35px; padding-right:10px">
<?php
include ('facebook/facebook.php');
$facebook = new Facebook(array( 'appId' => 'xxxxx',
'secret' => 'xxxx',
'cookie' => true ));
$session = $facebook->getUser();
$me = null;
if ($session) {
try {
$me = $facebook->api('/me');
}
catch (FacebookApiException $e) {
echo $e->getMessage();
}
}
if ($me) {
$logout = $facebook->getLogoutUrl();
echo "<button class='btn btn-primary'></button";
} else {
$login = $facebook->getLoginUrl();
echo "<a href='$login'>Authorize</a>";
}
?>
</div>
Get the latest Facebook SDK for PHP - the one you are using is about 2 years old and not supported .
https://developers.facebook.com/docs/php/gettingstarted/4.0.0
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.
I'm using the following code as part of my facebook application that get user's permissions (mainly : likes ). This code will detect if the user is a fan of a page or not and based on that it will show some content or redirect him to another page, if he is not a fan. The main problem is that it works only one time or two times and then it shows nothing.
http://pastebin.com/RxefpmzD
<?php
require 'lib/facebook.php';
$facebook = new Facebook(array(
'appId' => 'XXXXXXXXXXXXXXXXXX',
'secret' => 'XXXXXXXXXXXXXXXXXXXXXXXXXX',
));
$user = $facebook->getUser();
if ($user) {
try {
$likes = $facebook->api("/me/likes/333605930105938");
if( !empty($likes['data']) )
echo "<iframe width=\"745\" height=\"535\" src=\"http://www.youtube.com/embed/".$donnees['link']."?fs=1&autoplay=1&loop=1\" frameborder=\"0\" allowFullScreen=\"\"></iframe>";
else
echo "<iframe width=\"745\" height=\"535\" src=\"scren.php?id=".$donnees['id']."\" frameborder=\"0\" allowFullScreen=\"\"></iframe>";
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl(array(
'scope' => 'user_likes'
));
}
?>