Topic-icon Jfbconnect not detecting Community Builder

Active Subscriptions:

None
13 years 11 months ago #24271 by rajkum
Hi Alex,
Thanks for your response. Actually i am looking for a point when the user CLICKs the button Login with Facebook and i get the response and i will parse that response to see whether user gives the permission to facebook application or not. For your reference i am posting the code which i have used if i do the same functionality without JfbCONNECT

$graph_url = "graph.facebook.com/".$info."?access_token=" . $info;
$response = curl_get_file_contents($graph_url);
$decoded_response = json_decode($response);

//Check for errors
if ($decoded_response->error) {
// check to see if this is an oAuth error:
if ($decoded_response->error->type== "OAuthException") {
// Retrieving a valid access token.
$dialog_url= "www.facebook.com/dialog/oauth?"
. "client_id=" . $app_id
. "&redirect_uri=" . urlencode($my_url);
echo("<script> top.location.href='" . $dialog_url
. "'</script>");
}
else {
echo "other error has happened";
}
}
else {
// success
echo("success" . $decoded_response->name);
echo($access_token);
}

// note this wrapper function exists in order to circumvent PHP’s
//strict obeying of HTTP error codes. In this case, Facebook
//returns error code 400 which PHP obeys and wipes out
//the response.
function curl_get_file_contents($URL) {
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $URL);
$contents = curl_exec($c);
$err = curl_getinfo($c,CURLINFO_HTTP_CODE);
curl_close($c);
if ($contents) return $contents;
else return FALSE;
}
Where this functionality is implemented in JFBConnect source code.
I added your code to increase the validity of ACCESS-TOKEN and its working perfectly.

Thanks
Rajneesh
The topic has been locked.
Support Specialist
13 years 11 months ago #24286 by alzander
If you want to check for specific permissions, the login() function I mentioned above would be a great candidate. There's already some checks before that is called to make sure the user has validated your application though. If you'd prefer to do it before JFBConnect does those checks, you can modify the /components/com_jfbconnect/controller.php file and edit the loginFacebookUser() function. That is what is immediately called after the user hits the "Login With Facebook" button.

If they haven't approved the app with even the minimal permissions though, that won't even be called because that function is only triggered by Facebook itself when the user logs in, just so you know.

Hope that helps!
Alex
The topic has been locked.
Active Subscriptions:

None
13 years 11 months ago #24400 by rajkum
Hi Alex,

Actulaly i am developing a website in which a user login using his/her facebook account. As soon as the user login and grants the requested permissions to the facebook application, a page will appear with Entertainment articles. As soon as the user clicks any article, i need to pass that information ( information contains facebook Id and some information associated with the clicked article such as tags) to a reasoning engine so that i can display something useful to the user based upon this information. I need to get the facebook ID of the user. One way is use the following

FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
// the user is logged in and has authenticated your
// app, and response.authResponse supplies
// the user's ID, a valid access token, a signed
// request, and the time the access token
// and signed request each expire
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
} else if (response.status === 'not_authorized') {
// the user is logged in to Facebook,
// but has not authenticated your app
} else {
// the user isn't logged in to Facebook.
}
});

How can i use getLoginStatus function of JFBConnect to call it independently with my onclick() javascript functionality. If there is any other alternative then please suggest me.

Please help me out, my project deadline is very close.

Thanks
Rajneesh
The topic has been locked.
Support Specialist
13 years 11 months ago #24416 by alzander
If you need to do something in Javascript, then you'd need to edit the components/com_jfbconnect/includes/jfbconnect.js file. The jfbc.login.on_login() function is what you'd want to edit. Just make sure you add it before the self.location = ... line toward the bottom of that function.

Alternatively, if you want the user's Facebook User ID using PHP, you can use:
$jfbcLibrary = JFBConnectFacebookLibrary();
$fbUserId = $jfbcLibrary->getFbUserId();
That code will only return a valid Facebook User ID if the user has approved your app. You can then check for permissions or do any other code necessary as specified a few posts above.

Again, hope that helps narrow down where you should add your code, but if you need more help, just let us know.

Thanks,
Alex
The topic has been locked.
Support Specialist
13 years 11 months ago #24417 by alzander
Actually, I just re-read your post. If you simply want to use Javascript to check if the user is logged in and get their ID, you can do that anywhere. JFBConnect automatically includes and initializes the Facebook Javascript library. Therefore, in your code on any onclick calls, you can easily add the following code:
FB.getLoginStatus(function(response) { 
  if (response.status === 'connected') { 
    // the user is logged in and has authenticated your 
    // app, and response.authResponse supplies 
    // the user's ID, a valid access token, a signed 
    // request, and the time the access token 
    // and signed request each expire 
    var uid = response.authResponse.userID; 
    var accessToken = response.authResponse.accessToken; 
  } else if (response.status === 'not_authorized') { 
    // the user is logged in to Facebook, 
    // but has not authenticated your app 
  } else { 
    // the user isn't logged in to Facebook. 
  } 
});
There is no specific JFBConnect method in Javascript to do getLoginStatus, that's a core part of the Facebook Javascript library.

Again, hope that helps,
Alex
The topic has been locked.
Active Subscriptions:

None
13 years 10 months ago #24584 by rajkum
Hi Alex,

Jfbconnect user map table contains two user ids j_user_id and fb_user_id. It means when a user login with his facebook account, jfbconnect create two user joomla user and joomla facebook user and send the email to the user with joomla user login information.I want to disable email feature and want to create only joomla facebook user.

Thanks
Rajneesh
The topic has been locked.
Support Specialist
13 years 10 months ago #24598 by alzander
Rajneesh,
JFBConnect doesn't create 2 accounts, we create one: a Joomla user. The j_user_id table stores the Joomla id for that user that was created and the fb_user_id stores the user's Facebook ID so we know how the two accounts are linked. You absolutely need to have a Joomla user on the site for Joomla and other 3rd party extensions to be able to let that user do anything as they need a Joomla user for their functionality.

As for disabling new user emails, if you edit the /components/com_jfbconnect/controllers/loginregister.php file, at line 256, you'll see:
$this->sendNewUserEmails($jUser);
Simply comment out that line and no new user registration emails will be sent.

Hope that helps,
Alex
The topic has been locked.
Active Subscriptions:

None
13 years 10 months ago #24644 by rajsin
Hi Alex,

I am trying to insert a php code inside the login function and i need a access token (below in the code token12 ), so that i can request the information on user behalf and as soon as i get
the information, i will parse the json format and will save into my database. Right now i am not using Community builder plug-in.



$jfbcLibrary = JFBConnectFacebookLibrary::getInstance();
$fbUserId = $jfbcLibrary->getFbUserId();

$graph_url = "graph.facebook.com/".$fbUserId."?access_token=".$token12; //token 12


$user_name = "joomla";
$password = "*****";
$database = "*****";
$server = "192.168.1.166";

$con = mysql_connect($server, $user_name, $password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
else
print "Connection to the Server opened";

$db_found = mysql_select_db($database);
if ($db_found) {
print "Database Found";
}
else {
print "Database NOT Found";
}




$ch=curl_init($graph_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$r=curl_exec($ch);
curl_close($ch);

$arr = json_decode($r,true);

$user_facebook_id=$arr->id;
$user_name=$arr->name;

$data = mysql_query("INSERT INTO jmzr4_m_users (facebook_id,name) VALUES('$user_facebook_id','$user_name')");

if (!$data)
{
die('Could not connect to database table: ' . mysql_error());
}
else
print "Connection to the table";


mysql_close($con);



please help me out.I will appreciate i will reply quickly.

Thanks
Rajneesh
The topic has been locked.
Active Subscriptions:

None
13 years 10 months ago #24645 by rajkum
Hi Alex,

I am trying to insert a php code inside the login function and i need a access token (below in the code token12 ), so that i can request the information on user behalf and as soon as i get
the information, i will parse the json format and will save into my database. Right now i am not using Community builder plug-in.



$jfbcLibrary = JFBConnectFacebookLibrary::getInstance();
$fbUserId = $jfbcLibrary->getFbUserId();

$graph_url = "graph.facebook.com/".$fbUserId."?access_token=".$token12; //token 12


$user_name = "joomla";
$password = "*****";
$database = "*****";
$server = "192.168.1.166";

$con = mysql_connect($server, $user_name, $password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
else
print "Connection to the Server opened";

$db_found = mysql_select_db($database);
if ($db_found) {
print "Database Found";
}
else {
print "Database NOT Found";
}




$ch=curl_init($graph_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$r=curl_exec($ch);
curl_close($ch);

$arr = json_decode($r,true);

$user_facebook_id=$arr->id;
$user_name=$arr->name;

$data = mysql_query("INSERT INTO jmzr4_m_users (facebook_id,name) VALUES('$user_facebook_id','$user_name')");

if (!$data)
{
die('Could not connect to database table: ' . mysql_error());
}
else
print "Connection to the table";


mysql_close($con);



please help me out.I will appreciate i will reply quickly.

Thanks
Rajneesh
The topic has been locked.
Active Subscriptions:

None
13 years 10 months ago #24646 by rajkum
which function provides me the this access token with respect to the current user.
The topic has been locked.