I have very simple PHP code from Facebook tutorial:
$facebook = new Facebook(array(
'appId' => 'xxxx..',
'secret' => 'xxx...',
));
when I test the $facebook
object, I see that it hasn't any properties.
I have included the Facebook PHP file. Otherwis开发者_开发问答e it should throw an error. So linking libraries is not my problem.
I have checked appId
and secret codes and they are correct too. I don't know why facebook object is ampty and it doesn't displays any error.
I am using the newest version of PHP SDK. I updated it just today. I am using the same application to log in the user by Javascript Facebook SDK, so I think, my application is set correctly.
Seems perfectly allright.. Add some more code to check and see whether its working and querying the API. Here are some additions that u should add and check to see it its working.
<?php
set_time_limit(0);
include_once 'facebook.php';
$facebook = new Facebook(array(
'appId'=>'******',
'secret'=>'*****',
'cookie'=>true
));
$session=$facebook->getSession();
$me= null;
try
{
$userId=$facebook->getUser();
$me=$facebook->api('/me');
echo $me['first_name'] . " " . $me['last_name'];
}
catch (FacebookApiException $e)
{
echo $e->getMessage();
}
Make sure you add the "try catch" in any of your facebook API code.. Itll show you the error if it encounters any.
If youve got ANY more questions or u feel i didnt answer your question properly, feel free to comment and ill get back to you.
Try to check if you got the settings to show errors sometimes they need to be explicitly declare like this:
ini_set('display_errors', 1);
As I find out, I haven't an empty Facebook object. I am using Krumo
class to print the object content and it is probably set not to display protectec attributes. When I use the PHP print_r function, I get this object:
Facebook Object ( [appId:protected] => xxx [apiSecret:protected] => xxx [user:protected] => [signedRequest:protected] => [state:protected] => [accessToken:protected] => [fileUploadSupport:protected] => )
精彩评论