facebook authentication / login trouble

Posted by salmane on Stack Overflow See other posts from Stack Overflow or by salmane
Published on 2010-05-13T10:17:58Z Indexed on 2010/05/13 10:24 UTC
Read the original article Hit count: 250

Filed under:
|

I have setup facebook authentication using php and it goes something like this first getting the authorization here :

https://graph.facebook.com/oauth/authorize?client_id=<?= $facebook_app_id ?>&redirect_uri=http://www.example.com/facebook/oauth/&scope=user_about_me,publish_stream

then getting the access Token here :

$url = "https://graph.facebook.com/oauth/access_token?client_id=".$facebook_app_id."&redirect_uri=http://www.example.com/facebook/oauth/&client_secret=".$facebook_secret."&code=".$code;"

function get_string_between($string, $start, $end){ 
    $string = " ".$string; 
    $ini = strpos($string,$start); 
    if ($ini == 0) return ""; 
    $ini += strlen($start); 
    $len = strpos($string,$end,$ini) - $ini; 
    return substr($string,$ini,$len); 
} 


$access_token = get_string_between(file_get_contents($url), "access_token=", "&expires=");     

then getting user info :

$facebook_user = file_get_contents('https://graph.facebook.com/me?access_token='.$access_token);

$facebook_id = json_decode($facebook_user)->id;
$first_name = json_decode($facebook_user)->first_name;
$last_name = json_decode($facebook_user)->last_name;

this is pretty ugly ( in my opinion ) but it works....how ever....the user is still not logged in...because i did not create or retrieve any session variables to confirm that the user is logged in to facebook...

which means that after getting the authentication done the use still has to login ....

first: is there a better way using php to do what i did above ? second: how do i set/ get session variable / cookies that ensure that the user doesnt have to click login

thanks for your help

© Stack Overflow or respective owner

Related posts about facebook

Related posts about php