suddenly facebook connect stopped working - facebook

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.

Related

An empty array of likes even though correct permissions - Facebook App

I'm going slightly mad because of my problem. I prepared facebook app based on facebook-php-sdk. My app's permisions are:
publish_acions, user_location, user_likes, friends_likes
Everything goes correct with that code:
$facebook = new Facebook(array(
'appId' => '####',
'secret' => '####',
));
I can also receive
$user = $facebook->getUser();
$user_profile = $facebook->api('/me');
$userId = $user_profile['id'];
But I can't receive
$user_likes = $facebook->api('/me/likes/');
It just gives me an empty array (I'm quite sure I like the page). So what's the reason?
Thanks in advance...
First of all: Use The JavaScript for the login process, it´s much easier to handle and debug. Also, it´s better for the usability, because it does not redirect: https://developers.facebook.com/docs/reference/javascript/FB.login/v2.1
Use the "scope" parameter as it is mentioned in the docs and check if the required permissions are really asked for in the authorization popups.
Btw, the correct endpoint would be /me/likes (without the slash at the end), just another idea why it does not work.
And then there is the review process, most permissions (like user_likes) need to get approved by Facebook before they can be used for other users (except for users with a role in the App settings). Check out the changelog and the review guidelines for more information:
https://developers.facebook.com/docs/apps/changelog
https://developers.facebook.com/docs/apps/review/login
Friend permissions are deprecated btw, there is no "friends_likes" anymore.

Changes to make in the app for new version of facebook PHP SDK

We are using old version of Facebook connect PHP SDK, what changes we need to do to make the app working with the new changes (Currently the app is not working due to FB app version changes)
Update your PHP SDK, connection needs change, getSession() is no longer available, use getUser() instead. Also if you are using too old PHP SDK (before Graph API) then you may have to update some API calling functions.
Overall connection is like below:
$facebook = new Facebook(array(
'appId' => '111111111',// your appId here
'secret' => '1a1a1a1a1a1a1',// your app secret here
));
$user = $facebook->getUser();
if ($user) {
try {
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl();
echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
exit;
}
Short answer: authentication flow and REST API deprecation
Long answer: there have been two major version changes since version 2.1. You should go through the facebook developer blog for clear understanding of changes.
Some of the announcement links below:
Developer Roadmap Update: Moving to OAuth 2.0 + HTTPS
Upgrade to PHP SDK v3.0.0
Migrating to OAuth 2.0 update: PHP SDK v.3.1.1
The new login flow using PHP SDK looks like this:
$facebook = new Facebook(…);
$user = $facebook->getUser();
if ($user) {
// proceed knowing you have a logged in user who's authenticated
} else {
// proceed knowing you require user login and/or authentication
}
If you are storing session keys at the moment, they will not work anymore. You'll need to migrate to use oauth access tokens. This SO link discusses this process: Converting Facebook session keys to access tokens
Also, if yours is a canvas app using legacy auth, you'll need to make changes as described on this page: Migrating to OAuth 2.0

$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 authentication with codeigniter (active access token must...)

I sign in with FB fine if I directly create a page at domain.com/someurl.php
The moment I copy the same code (inc html) into a view file with codeigniter and go to domain.com/login/someurl.html it doesn't work. By it doesn't work I mean, I get an exception if i try to access /me after signing into facebook.
The message reads "An active access token must be used to query information about the current user"...
In my controller i have my index function and all it does is load the view with the facebook login code.
I thought I may be doing something wrong but I copied the sample.php from the facebook sdk and paste it into the view file and the same thing happens. If i copy the sample code into the file at someurl.php it then works as expected...given the situation I suspected it may be something to do with codeigniter and possibly some config option I have that causes that behaviour...
I've been looking up the error for a while now and have found a few resources:
http://benbiddington.wordpress.com/2010/04/23/facebook-graph-api-getting-access-tokens/
Facebook access_token invalid?
Facebook authentication issue
https://github.com/facebook/php-sdk/wiki/AccessToken
but none of the suggested fixes have worked.
Right from the sample:
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
'appId' => 'APPID',
'secret' => 'SHHHH',
));
// Get User ID
$user = $facebook->getUser();
// We may or may not have this data based on whether the user is logged in.
//
// If we have a $user id here, it means we know the user is logged into
// Facebook, but we don't know if the access token is valid. An access
// token is invalid if the user logged out of Facebook.
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();
}
It doesn't work in the view and I'm stumped as to why or why none of the fixes or "precautions" such as not using type or ensuring the redirect url is the same etc, work.
EDIT:
I'm trying to avoid using domain.com/somefile.php and instead use a view file like every other page...
The issue has cropped up in other places such as the Elliot Houghin fb/CI library.
I found a solution documented in a tutorial here:
http://www.dannyherran.com/2011/02/facebook-php-sdk-and-codeigniter-for-basic-user-authentication/
The problem could be cause from one of several issues pointed out on a an issue on Elliot's github repo. I tried many of the suggested "fixes" but the one that seemed to help was not using the facebook instance as a class property. After trying the tutorial at the above link I tried a fresh install of CI again and created a facebook instance inside the function, the API calls with the FB SDK then worked and had no problems so far.
Bug report with suggested fixes #
https://github.com/elliothaughin/codeigniter-facebook/issues/5

Facebook API to retrieve wall feed

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.