Facebook application - server not responding - facebook

After the FBML problems I switched to iFrame apps. All well for now except that 2 things:
1) if I did not entered in the app for a few hours and I try to enter, sometimes it gives me the error page that my server did not responded. It shows the Faceboob page with iFrame inside showing the error. After 1 or 2 refreshes it's working fine.
2) I implemented the new SDK with login like this
$facebook = new Facebook(array(
'appId' => $fbID,
'secret' => $fbSecret,
'cookie' => true,
));
$user = $facebook->getUser();
$loginUrl = $facebook->getLoginUrl();
if ($user) {
try {
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
d($e);
$user = null;
}
}
if (!$user) {
echo "<script type='text/javascript'>
top.location.href = '$loginUrl';
</script>";
exit;
}
The problem is my first redirect, when user enters for the first time. It redirects to my server URL not my Facebook app URL. If I try to put it like this:
$loginUrl = $facebook->getLoginUrl(
array(
'redirect_uri' => 'http://apps.facebook.com/xxx/'
)
);
the login is entering in an infinite loop.
Any help solving this two problems is welcome:-)
Thanks

Darko4spain when the user is redirected back to your site, you can detect if is in iframe with javascript and send them back. I have same issue with my app. This is not a pretty fix but it works.
if (window!=window.top) {
//FB.Canvas.setAutoResize();
setTimeout("FB.Canvas.setAutoGrow()", 1400);
}else {
top.location.href = 'https://apps.facebook.com/AnotherFeed/?ref=redirect#comments';
}
example: https://anotherfeed.com/plugins/index.php will redirect you back to my canvas if you are not in the canvas.

Related

"facebook.com" missing from login page URL

I can not login with facebook from any applications, including from mine. This is caused by the lack of "facebook.com" in login page URL. When we click the login button, the URL should be
https://www.facebook.com/login.php?skip_api_login=1&api_key=XXX....
but in my case :
https://www./login.php?skip_api_login=1&api_key=XXX.. (without "facebook.com")
So, the web page can not display anything. It just happened today, everything was normal yesterday. I have try facebook basic example code and the problem still same. Here's the code :
<?php
require 'facebook.php';
$facebook = new Facebook(array(
'appId' => '137737616434442',
'secret' => 'XXX',
'baseurl' => 'http://localhost/facebookconnect/login/example.php',
));
$user = $facebook->getUser();
if ($user) {
try {
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
if ($user) {
$logoutUrl = $facebook->getLogoutUrl(array( 'next' => 'http://localhost/facebookconnect/login/example.php' ));
session_destroy();
} else {
$loginUrl = $facebook->getLoginUrl(array(
'scope' => 'email,user_birthday,friends_birthday,publish_stream,user_location,friends_location,user_work_history,user_likes,friends_work_history,user_about_me,friends_about_me,user_hometown',
'redirect_uri' => 'http://localhost/facebookconnect/login/example.php'));
}
$naitik = $facebook->api('/naitik');
?>
Any help would be greatly appreciated, thank you
I think it's Facebook app problem. Looks like the problem occurs everywhere.
I restart my connection and, everything is back to normal. Looks weird, but it works.
My Facebook page is missing today (August 28, 2013) too! It was there at midnight last night but won't load today! My Outlook/Hotmail won't work either. Loads but won't open anything. I think it's been hijacked after a friend's hotmail was hijacked. This computer is going to the hospital tomorrow. Until then it is being unplugged from the internet.

facebook php sdk automatically logs out user

I am trying to integrate facebook login in my website.
I am facing a weird problem wherein the user keeps getting logged out almost every 10 minutes from my website, although he remains logged in to facebook:
I don't have much clue about the cause of the error, but this might help. I had some error in my javascript code and since during that time, javascript was not being executed, I somehow remained logged in.
For implementing facebook login i am using geloginUrl and getLogoutUrl functions in php, I have added some code to post on friends' wall etc in javascript as well.
That is all the relevant information according to me.
Let me know, if any additional details might be required to answer this question correctly.
This is what my code looks like:
$user = $facebook->getUser();
if ($user) {
try {
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
$user = 0;
}
}
if ($user) {
setcookie('uid', $user, time()+36000, '/', 'mywebsite.com');
setcookie('uname', $user_profile['name'], time()+36000, '/', 'mywebsite.com');
} else {
setcookie('uid', $user, time()+36000, '/', 'mywebsite.com');
setcookie('uname', $user_profile['name'], time()+36000, '/', 'mywebsite.com');
}
$loginUrlParams = array(
'scope' => 'email,user_activities,friends_activities,friends_interests,user_interests',
'redirect_uri' => 'http://mywebsite.com/getfbToken.php'
);
$loginUrl = "";
$logoutUrl = "";
$logoutUrlParams = array( 'next' => 'http://mywebsite.com/logout.php' );
// getting login url from facebook if user is invalid
if (!$user)
$loginUrl = $facebook->getLoginUrl($loginUrlParams);
else
$logoutUrl = $facebook->getLogoutUrl($logoutUrlParams);

Facebook api authorization in IE [duplicate]

Im making a facebook canvas app. To get the users info im using the PHP SDK:
<?
$app_id = "";
$secret="";
$canvas_page = "";
$auth_url = "";
$facebook = new Facebook(array(
'appId' => '',
'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;
}
}
// Login or logout url will be needed depending on current user state.
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl();
}
$user = $facebook->api('/me');
?>
Everything works fine in all browsers except on IE (all versions). When I click a link to another page inside the app, i get the next error:
Fatal error: Uncaught OAuthException: An active access token must be used to query
information about the current user. thrown in
/hermes/bosoraweb019/b2365/ipg.zicedcom/metrik/fbapp/fb/base_facebook.php on line
The code i just showed is in all pages inside the app, and i only get this problem in IE
Thanks!
It seems that for IE you need to enable 3rth party cookies (p3p). Just changed changed the header with php:
<? header('P3P: CP="NOI ADM DEV PSAi NAV OUR STP IND DEM"'); ?>

Facebook application : Doesn't redirect to OAuth in an iFrame

I am currently developing a facebook application using the php sdk and the js sdk. (I need both of them)
When a user has not yet authorized the application and loads the canvas page (https://apps.facebook.com/app_name/), nothing happens, he just gets a blank page with the facebook bar on top.
But if he loads the direct url of the application (https://my_app.mydomain.com), it works fine and he is redirected to the OAuth Dialog. If he authorizes the application, he is then redirected to https://apps.facebook.com/app_name/ and the iframe loads correctly.
If the user has already authorized the applications, both links are working (https://apps.facebook.com/app_name/ and https://my_app.mydomain.com).
Here is my authentication code :
<?php
require 'php-sdk/facebook.php';
$facebook = new Facebook(array(
'appId' => '327991330620101',
'secret' => '79asecretcc4300',
'cookie' => true
));
$user = $facebook->getUser();
if ($user) {
try {
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
$user = null;
}
}
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$params = array(
'scope' => 'publish_stream',
'redirect_uri' => 'https://apps.facebook.com/quiet_quies/'
);
$loginUrl = $facebook->getLoginUrl($params);
header('Location: ' . $loginUrl);
}
Does anybody have an idea about this ? It's really driving me mad...
Thanks for you help.
yes, #CBroe is right, in your php code try replacing header('Location: ' . $loginUrl); line with
echo "<script language=javascript>top.location.href ='".$loginUrl."'</script>";
it should work then.

facebook app oauth error (can not be displayed in frame)

I just wanted to create a FB app. I went to developers.facebook.com/apps, set up a new app, created a new folder on my server, copied an old (working) app into the folder, changed the app id, secret, canvas page and canvas url in my configuration file... and it did not work.
It displayed an error: "this content can not be displayed in frame".
I would be grateful if you could help me. Thanks.
I copy here my config file: (I intentionally removed the app id and secret here.)
// Facebook App ID/API Key
$appId = '';
// Facebook App Secret
$secret = '';
// Facebook Canvas Page
$redirect_uri = 'https://apps.facebook.com/appname/';
// Facebook Canvas URL
$canvas_url = 'https://myhost.com/appname/';
// Facebook App Permissions
$scope = 'email, publish_actions';
// Configure Facebook connection
require 'facebook.php';
$facebook = new Facebook(array(
'appId' => $appId,
'secret' => $secret,
'cookie' => true,
));
$user = $facebook->getUser();
$loginUrl = $facebook->getLoginUrl(array(
'redirect_uri' => $redirect_uri,
'scope' => $scope,
));
$logoutUrl = $facebook->getLogoutUrl();
if ($user) {
try {
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
$user = null;
}
} else {
header("Location: $loginUrl");
}
You should use JavaScript to redirect the user to the login URL using top.location = '{url}', and then use the login redirect url to send them back to your application. Facebook doesn't allow you to use facebook within an iframe, that why you are seeing that error message - pretty self explanatory.
It displays a "this content can not be displayed in frame" errormessage.
And what about this message gives you trouble understanding?
You can't call the auth dialog in an iframe, because it would enable phishing if the user can’t check the sites address.