2012-04-06 2 views
0

http://apps.facebook.com/karmabalance/는 FB 권한이 내 FB 앱에서 작업 로그인 및 인증을 얻기 위해 노력하고 올바르게

동작하지 않습니다,하지만 재미 물건을 할 것으로 보인다. 기본적으로 내가 원하는 것은 사용자가 내 앱을 클릭 할 때 fb가 로그인하여 앱을 승인했는지 확인하고 그 후에 프로그램을보고 데이터베이스를 확인해야하는 경우입니다. 그것들은 이미 사용자 FB ID를 가진 데이터베이스의 레코드입니다. 레코드가 없다면 프로그램에서 사용자를 작성하여 acct에 보내야합니다. 페이지에서 사용자가 사용자 이름을 입력 할 수있게합니다. 레코드가 있으면 사용자를 앱 홈 페이지로 보내려고합니다.

나는 그것이 작동한다고 생각했지만, 여전히 옳지 않았고, 나는 이유를 알 수 없다. 여기 내 코드가있다. 나는 이것도 할 수있는 더 좋은 방법이 있다고 확신합니다, 나는 초보자입니다, 그래서 나는이 모든 것을 알아 내려고 노력하고 있습니다. 어떤 도움을 주시면 감사하겠습니다. 사용자가 내 응용 프로그램을 클릭하면

감사

은이의 index.php 페이지로 이동합니다.

<?php 
require 'config.php'; 

session_start(); 

$usercheck = $user_profile['id']; 

$result = mysql_query("SELECT FBID FROM PLAYER WHERE (FBID = '$usercheck') "); 

if ($facebook->getUser()) 
{ 

    if(mysql_num_rows($result)) 
    { 
     header('location: Home.php'); 
    } else 
    { ?> 
     <p>Please choose a Username for yourself. </p> 
      <form action='includes/signup.php' method='post'> 
      <fieldset style="width:600px";> 
      <label>Username</label> 
      <input name='username' type='text' value='<? if ($facebook->getUser()) 
        {echo'Choose a Username';} ?>' /> 

      <input name='submit' type='submit' value='submit' /> 
      </fieldset> 
      </form> 
    <? } 
} else 
    { ?> 
    <p>Sign up with Facebook <fb:login-button perms='email'> Connect</fb:login-button> 

It only takes a few seconds</p> 

<div id='fb-root'></div> 

     <script src='http://connect.facebook.net/en_US/all.js'></script> 

     <script> 

     FB.init({ 

      appId:'334230339967350', cookie:true, 

      status:true, xfbml:true 

     }); 

     FB.Event.subscribe('auth.login', function(response) { 

     window.location.reload(); //will reload your page you are on 

     }); 

     </script> 
    <? } 

?> 

설정 파일 : 여기

<?php 
//Facebook Configuration 
require 'facebook-php-sdk/src/facebook.php'; 

$app_id = "xxxxxxxxxxxx"; 
$app_secret = "xxxxxxx"; 
$facebook = new Facebook(array(
     'appId' => $app_id, 
     'secret' => $app_secret, 
     'cookie' => true 
)); 

// 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; 
    } 
} 

// login or logout url will be needed depending on current user state. 
if ($user) { 
    $logoutUrl = $facebook->getLogoutUrl(); 
} else { 
    $loginUrl = $facebook->getLoginUrl(); 
} 


//SQL Configuration 

// i start most if not all pages with this depending on what Im using it for. 

    $host = 'localhost'; // host name OR IP 

    $username = 'security';//username 

    $pass = 'blockedout'; //password 

    $dbname = 'Security'; // Database Name 

    $conn = mysql_connect($host, $username, $pass) or die(mysql_error()); 

    if ($conn) 

    { 

     mysql_select_db($dbname) or die(mysql_error()); 

    } 

    else 

    { 

     echo 'Connection failed.'; 

    } // The above code connects to your database or errors if it cannot connect. 

// Again this is simple, security is your own priority. 

//GLOBAL VALUES?? 

$usercheck = $user_profile['id']; 

$usernamequery = mysql_query("SELECT UserName FROM PLAYER WHERE (FBID = '$usercheck') "); 
$username = mysql_fetch_array($usernamequery); 

$levelquery = mysql_query("SELECT LevelID FROM PLAYER WHERE (FBID = '$usercheck') "); 
$level = mysql_fetch_array($levelquery); 


$result = mysql_query("SELECT FBID FROM PLAYER WHERE (FBID = '$usercheck') "); 


?> 

그리고는 signup.php 페이지

<? 

require_once '../config.php'; 



//here you could add checks for any empty fields using (!($_POST['first_name'])) 

$first_name = $user_profile['first_name']; // this line will collect our information from the 

// field in our form that has the facebook first_name in it. 

$last_name = $user_profile['last_name']; // same as above 

$email = $user_profile['email']; //same as above 

$id = $user_profile['id']; //same as above 

$username1 = $_POST['username']; 

$query = mysql_query 
     (" 
     INSERT INTO PLAYER (FirstName, LastName, EMail, FBID, UserName, Status, LevelID, Cash, LifePoints, RespectPoints, ReputationPoints, UpgradePoints, HealthPercent) 
     VALUES ('$first_name', '$last_name', '$email', '$id', '$username1', '1', '1', '25000', '3', '3', '3', '20', '100') 
     ") 
     or die(mysql_error()); 

// The query will insert our fields in to the database as the above line shows, make 

//sure your database table headers are exactly correct otherwise this will not work 



// You can now either send an email or if you wanted header to a new page. This is 

//up to you. Tutorials on google will show you how to do this part 

if($query){ 

header('location: ../Home.php'); 

}else { 

echo 'error adding to database';  

} 

?> 

답변

0

당신은 사용자의 OAuth는 토큰을 누락입니다. 당신이 당기고 자하는 사용자의 손잡이 다. 아직도 혼란 스럽다면 알려주십시오.

+0

감사합니다. 그래, 내가 그 일을하고 있다고 생각했다. '// 사용자 ID 얻기 $ user = $ facebook-> getUser(); if ($ user) { { // 로그인 한 사용자가 인증되었음을 알리십시오. $ user_profile = $ facebook-> api ('/ me'); } catch (FacebookApiException $ e) { error_log ($ e); $ user = null; } } ' 아마도 올바른 방향으로 나를 더 자세히 조사해 볼 수 있습니까? –

관련 문제