2012-04-06 4 views
0

http://apps.facebook.com/karmabalance/はFBの承認は、私は私のFBのAppに取り組んでログインし、認証を取得しようとしています正しく

仕事を得ることはできませんが、面白いものをやっているようです。基本的に私が望むのは、ユーザーが自分のアプリケーションをクリックしたときに、ログインしてアプリを承認したことを確認するためにfbにチェックを行い、その後にデータベースのチェックを行うプログラムが必要な場合ですそれらはすでにUser FB IDを持つデータベース内のレコードです。彼らがレコードがない場合、私はプログラムがユーザーをcreate 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ページでは、ユーザーのOAuthトークンが欠落している

<? 

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

です。あなたが引っ張りたいユーザのハンドルです。 あなたがまだ混乱している場合は、教えてください。

+0

ありがとう、ええ、私はそれをやっていたと思った。 '//ユーザIDを取得 $ user = $ facebook-> getUser(); if($ user){ try { //ログインしたユーザーが認証済みであることを確認します。 $ user_profile = $ facebook-> api( '/ me'); } catch(FacebookApiException $ e){ error_log($ e); $ user = null; } } おそらく、私は正しい方向に向かって、より多くの調査を開始することができますか? –

関連する問題