안녕 개인적인 SQL 데이터베이스에 Facebook 데이터 (로그인 데이터)를 저장하는 데 문제가 있습니다. 여기 내 코드를 찾을 수 있습니다. 먼저 색인 페이지를 사용한 다음 로그인 페이지를 사용하여 데이터베이스에 내 Facebook 데이터 로그인을 저장합니다. 로그인 페이지에서 내 user_page로 리디렉션됩니다. 내 user_page로 리디렉션 때 페이스 북의 데이터가 저장되지 않고, 내가 링크를 https://localhost/project/login.php?error_code=901&error_message=This+app+is+in+sandbox+mode.++Edit+the+app+configuration+at+http%3A%2F%2Fdevelopers.facebook.com%2Fapps+to+make+the+app+publicly+visible.&state=7504294781f7ae045299820cb5c40ead#_=_
facebook-php-sdk가 데이터베이스에 데이터를 저장하지 않습니다.
인덱스 페이지 코드
<?php
require 'facebook-php-sdk/src/facebook.php';
define('APP_URL', 'https://localhost/project/login.php');
define('APP_PERMISSIONS', '');
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
'appId' => 'APPID',
'secret' => 'SECRET',
'cookie' => true
));
$loginUrlParams = array(
'scope' => APP_PERMISSIONS,
'redirect_uri' => APP_URL,
);
// 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.
$fbuid = $facebook->getUser();
$user_profile = $facebook->api('/me');
// header('Location: user_page.php');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
header('Location: ' . $facebook->getLoginUrl($loginUrlParams));
exit;
}
}
else
{
header('Location: ' . $facebook->getLoginUrl($loginUrlParams));
exit;
}
?>
로그인 페이지 코드를 얻을 :
<?php
define("db_DATABASE", "phples");
define("db_SERVER", "localhost");
define("db_USER", "root");
define("db_PASS", "");
$conn=new mysqli(db_SERVER,db_USER,db_PASS,db_DATABASE);
require 'facebook-php-sdk/src/facebook.php';
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
'appId' => 'APPID',
'secret' => 'SECRET',
'cookie' => true));
// Get User ID
$user = $facebook->getUser();
if($user){
$user_profile = $facebook->api('/me');
$query = mysql_query("SELECT * FROM facebook_users WHERE oauth_provider = 'facebook' AND oauth_uid = ". $user_profile['id']);
$result = mysql_fetch_array($query);
if(empty($result)){
$query = mysql_query("INSERT INTO facebook_users (oauth_provider, oauth_uid, username) VALUES ('facebook', {$user_profile['id']}, '{$user_profile['name']}')");
header('Location: user_page.php');
}else{
header('Location: user_page.php');
}
}else{
header('Location: logout.php');
}
?>
을 사용자 _ 페이지 코드 :
<?
require 'facebook-php-sdk/src/facebook.php';
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
'appId' => 'APPID',
'secret' => 'SECRET',
'cookie' => true
));
// 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.
$fbuild = $facebook->getUser();
$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) {
$paramsout = array('next'=>'http://localhost/project/logout.php');
$logoutUrl = $facebook->getLogoutUrl($paramsout);
}
?>
샌드 박스 문제가 해결되었지만 메시지가 나타납니다. ** 주어진 URL 중 하나 이상이 앱 설정에서 허용되지 않습니다. 그것은 웹 사이트 URL 또는 Canvas URL과 일치해야합니다. 또는 도메인은 App 도메인 중 하나의 하위 도메인이어야합니다. ** 메인 페이지로 localhost/PHP/project/test2.php가 있습니다.이 링크는 내 페이스 북에 있습니까? 개발자 앱 설정? – Glenda
@Glenda 답변을 업데이트했습니다. –
을 확인하십시오. http : //localhost/PHP/project/test2.php를 https가 아닌 페이 스북 앱 페이지에 내 사이트 domein에 넣었습니다. 나는 또한이 appid와 비밀을 다른 이들과 공유합니다. – Glenda