4
I minimized my code as little as possible in order to isolate the error. I’ve reviewed the forum looking for a simple answer, but no hint solved this basic problem.
In the app settings, the only changes I made were filling in the url (localhost:81/Mb - I’ve already published the file and changed the domain and the result was the same) and set the Default Activity Privacy clause as Public in the App Center Permissions. I need to do something else?
This is a PHP page:
include_once 'libs/facebook/src/facebook.php';
$facebook = new Facebook(array(
'appId' => '###',
'secret' => '###',
'cookie' => true
));
$user = $facebook->getUser();
$login_url = $facebook->getLoginUrl();
echo 'Please <a href="' . $login_url . '">login.</a>';
if($user == null) {
print_r("user null " . $user);
} else {
print_r("user logged" . $user);
}
Although you are logged in to facebook and use another Chrome tab the result is "user null 0".
You gave permission to your application with the user account?
– Felipe Avelar
When do these permissions need to be given? I set up site dominance in the facebook developer session.
– Alexandre Bonfá
When you try to enter the site, It is to automatically divert to facebook, Profile allow access to the app information. Also, which URL did you put in for the app? If you’re testing locally, you need to put in localhost. Also, where do you have it
###
are the ID and the secret of the app right? otherwise, not even chance to funfar.– Felipe Avelar
Felipe, yes to everything you mentioned: I’m testing locally and the saved URL is localhost and the appid and Secret codes are properly copied from the same page of the app on Facebook. And yet, user = null.
– Alexandre Bonfá
Probably the user is not logged in to Facebook when accessing your page. In the SDK for Javascript (with which I have some experience), you can request the login, but in the SDK for PHP I honestly do not know. Looking at this official example, it looks like you need to provide a link to the login: https://developers.facebook.com/docs/php/howto/profilewithgraphapi/
– Luiz Vieira
That’s exactly it, you shouldn’t be ordering the login. When the $user is equal to
null
, you should use:$login_url = $facebook->getLoginUrl();
 echo 'Please <a href="' . $login_url . '">login.</a>';
– Felipe Avelar
Luiz, Felipe - although the user is already logged in, after all I was using Facebook in the neighbor tab (maybe I’m not understanding the concept of logged in), I created HREF to log in. When I click on "login", the URL changes "? code=XXXXX", but nothing happens. F5 does not change anything...
– Alexandre Bonfá
So, man, what happens when you click the login is you redirect yourself to facebook and from there, you give the permissions to the app. Like when you’re going to access a new game, which says the app can post things on your wall instead, etc...
– Felipe Avelar
This is exactly what I wanted to happen... But this URL only appears: http://localhost:81/Mb/post_stalker.php? code=aqcpb3nxplwomhbyluci2hq-gzuSO9OqJ3R_Y2WU1IVSPWLuvPbRT9G3MOy3V6sPBGBmnx8zTryXM1-Figcw2lsv276vaiwfim2whszxfcesjjhywnzag4rmijpruropyxgo5ap3rhf6ntrldzp57j08zrcq_6huwz9mio5om8tuy2hsutbcififqso2rkazdwk2j7lqqb_0hx3ffizacgjjstjtjjjjgeydidm7wpvz9xd-wAO6ZXeHnQJRqJ7cSoufAdHaXxzkpoQ1JEpyFXc2rhmbrHqsk-roB78gMNYYUeTiC3pjiYD887-JmLY&state=b1385f1e529f520c3ca8733e00ed2141#=
– Alexandre Bonfá
Ah, got it, the permissions page isn’t showing up, is it? IT SEEMS TO BE PROBLEM with the app settings.
– Felipe Avelar
In the app settings, the only changes I made were filling in the url (http://localhost:81/Mb) and setting in App Center Permissions the Default Activity Privacy clause as Public. I need to do something more?
– Alexandre Bonfá
The ideal is to put as much information as possible editing the question itself to make it easier for everyone to understand the problem. If the new information is only in the comments, the chances of getting a reply decrease.
– Maniero
Does it have to be door 81? Maybe that’s why...
– Felipe Avelar
I thought that too. I already uploaded to the domain and continued with the same problem.
– Alexandre Bonfá
Add to the 'status' => true' initialization array
– Erik
Puts what you edited in a reply explaining how you did to solve the problem.
– Felipe Avelar
Thanks for the tip! I had already edited in the question itself and now I created an answer!
– Alexandre Bonfá