Example #1
0
 * not use this file except in compliance with the License. You may obtain
 * a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */
require '../src/Facebook/Facebook.php';
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook\Facebook(array('appId' => '191149314281714', 'secret' => '73b67bf1c825fa47efae70a46c18906b'));
// 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.
        $user_profile = $facebook->api('/me');
    } catch (Facebook\FacebookApiException $e) {
        error_log($e);
        $user = null;
    }
}
// Login or logout url will be needed depending on current user state.
Example #2
0
<?php

session_start();
require_once "fbRegistro.php";
$facebook = new Facebook\Facebook(['app_id' => '391126004384836', 'app_secret' => '4c9c259cf2e6e49270550c4d96fb196b', 'default_graph_version' => 'v2.5']);
$facebook_id = $facebook->getUser();
#Verifica el usuario
if ($facebook_id != 0) {
    //CONNECT TO THE MYSQL SERVER
    // Create connection o      localhost
    $con = mysqli_connect("localhost", "root", "root", "TOMO2");
    // Check connection
    if (mysqli_connect_errno()) {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
    //END CREATING CONNECTION //
    #Comprobar si el usuario existe
    $query = $mysqli->query("SELECT * FROM FacebookLogin WHERE id_fb = '{$facebook_id}'");
    $rows = $query->num_rows;
    if ($rows > 0) {
        #El usuario ya existe
        $datos = $facebook->get("/me");
        //var_dump();
        #Obtenemos los datos del usuario de MySQL
        $datos = $query->fetch_array(MYSQLI_ASSOC);
        #Inicio de sesion
        $_SESSION["facebook_id"] = $facebook_id;
        $_SESSION["username"] = $datos["username"];
        $_SESSION["email"] = $datos["email"];
        $_SESSION["oauth_provider"] = $datos["oauth_provider"];
        $_SESSION["oauth_uid"] = $datos["oauth_uid"];