이 코드는 사용자 데이터를 가져 와서 데이터를 직렬화하고 데이터베이스에 던집니다. 완벽하지는 않지만 잘 보입니다. 내가 여유 시간을 가질 때 이것을 편집 할 것이고, 나중에 쿼리 검색을 더 쉽게 할 수 있기 때문에 JSON으로 사용자 데이터를 인코딩하는 것이 좋습니다.
<?php
require 'facebook.php'; // USE FACEBOOK PHP SDK
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
'appId' => 'APPID',
'secret' => 'APPSECRET',
));
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// Get User ID
$user = $facebook->getUser();
/* We may or may not have this data based on whether the user is logged in.
If we have a $user id here, it means we know the user is logged into
Facebook, but we don't know if the access token is valid. An access
token is invalid if the user logged out of Facebook. */
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$dt = $facebook->api('/me');
$lk = $facebook->api('/me/likes');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// Handler for Login Status
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl(array("scope" => "email,user_birthday,user_likes,user_work_history,user_location,user_education_history"));
}
// ----------------------------------------------------------------------------------------
?>
<?php if (!$user): header ('Location:'.$loginUrl.''); //CHECKS IF USER IS LOGGED IN
else:
$con = mysql_connect("DATABASE IP","USERNAME","PASS");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
else{
$id = base64_encode(serialize($dt['id']));
$work = base64_encode(serialize($dt['work']));
$location = base64_encode(serialize($dt['location']));
$education = base64_encode(serialize($dt['education']));
$f_n = $dt['first_name'];
$l_n = $dt['last_name'];
$link = $dt['link'];
$u_n = $dt['username'];
$bd = $dt['birthday'];
$gdr = $dt['gender'];
$em = $dt['email'];
$sportsS = base64_encode(serialize($dt['sports']));
$languagedt = $dt['languages'];
foreach($languagedt as $item){
$language[] = $item;
}
$languageS = base64_encode(serialize($language));
$lk_dt = $lk['data'];
foreach($lk_dt as $value)
{
if ($value['category'] == "Musician/band" || $value['category'] == "Song"){
$fav_music[] = $value;
}
if($value['category'] == "Tv show"){
$fav_tvshow[] = $value;
}
if($value['category'] == "Book"){
$fav_book[] = $value;
}
if($value['category'] == "Movie"){
$fav_movie[] = $value;
}
if($value['category'] == "Games/toys"){
$fav_games[] = $value;
}
if($value['category'] == "Interest"){
$interest[] = $value;
}
if($value['category'] == "Professional sports team"){
$sport_team[] = $value;
}
// next is likes
if ($value['category'] != "Movie" && $value['category'] != "Musician/band" && $value['category'] != "Book" && $value['category'] != "Games/toys" && $value['category'] != "Tv show" && $value['category'] != "Professional sports team" && $value['category'] != "Interest" && $value['category'] != "Tv show" && $value['category'] != "Professional sports team" && $value['category'] != "Song") {
$likes[] = $value;
}
}
$fav_musicS = base64_encode(serialize($fav_music));
$fav_movieS = base64_encode(serialize($fav_movie));
$fav_bookS = base64_encode(serialize($fav_book));
$fav_tvshowS = base64_encode(serialize($fav_tvshow));
$sport_teamS = base64_encode(serialize($sport_team));
$fav_gamesS = base64_encode(serialize($fav_games));
$interestS = base64_encode(serialize($interest));
$likesS = base64_encode(serialize($likes));
mysql_select_db("database", $con);
$result = mysql_query("SELECT id, firstdone FROM users WHERE id='$id'");
$row = mysql_fetch_array($result);
$f_dn = $row['firstdone'];
$ctrl = $row['id'];
if (!$ctrl){
mysql_query("INSERT INTO users (id, language, fav_sports, education, location, work, first_name, last_name, link, username, birthday, gender, email, fav_music, fav_movie, fav_books, fav_tv, fav_sport, fav_games, interest, likes)
VALUES ('$id', '$languageS', '$sportsS', '$education', '$location', '$work', '$f_n', '$l_n', '$link', '$u_n', '$bd', '$gdr', '$em', '$fav_musicS', '$fav_movieS', '$fav_bookS', '$fav_tvshowS', '$sport_teamS', '$fav_gamesS', '$interestS', '$likesS')");
if ($_SERVER['REQUEST_URI'] == '/index.php') {
header('Location: /theprofilepage');}
}
else{
mysql_query("UPDATE users SET language='$languageS', fav_sports='$sportsS', first_name='$f_n', last_name='$l_n', link='$link', username='$u_n', birthday='$bd', gender='$gdr', email='$em', fav_music='$fav_musicS', fav_movie='$fav_movieS', fav_books='$fav_bookS', fav_tv='$fav_tvshowS', fav_sport='$sport_teamS', fav_games='$fav_gamesS', interest='$interestS', likes='$likesS', work='$work', location='$location', education='$education' WHERE id='$id'");
}
mysql_close($con);
}endif
?>
내가 PHP를 사용하는 것이 좋습니다 않습니다에 의해 U 그런 다음 "위치"기능에 의해, 헤더에 값으로 전달할 자바 스크립트를 사용하여 원하는 값을 얻을 수 있습니다 다음, PHP는 $ _GET와 그 정보를 얻을 것이다 SDK를 사용하여 인증 작업을 수행합니다. 그러나 당신이 선택합니다. 그리고 그것들을 함께 사용할 수도 있습니다.