Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

login with facebook using oauth

<?php
require "facebook.php";

$facebook = new Facebook(array(
    'appId'  => '3288@@@@@@@@@@',
    'secret' => 'ca2@@@@@@@@@@@@@@@@@@',
));

$user = $facebook->getUser();

I have made the app in the graph api and I have very little knowledge of graph api . I want to make a facebook login page in which user clicked on it and my app will generate the oauth for the user . after that i need the USERNAME, EMAIL,BIRTHDAY,NAME in the fre filled forms

I'm searching for this code from 3 night, but i didn't find the solution! If you have a suggestion, please write to me it! Please, anyway thanks and good day :)

like image 482
PHP_USER1 Avatar asked Nov 01 '22 16:11

PHP_USER1


1 Answers

You could use POST request to simulate login. I don't know Facebook's inputs, so you need to look closely into it's HTML, but here is a code for a simple PHP cURL request.

// Get cURL resource
$curl = curl_init();
// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_URL => 'https://www.facebook.com/login.php',
    CURLOPT_USERAGENT => 'Facebook Login',
    CURLOPT_POST => 1,
    CURLOPT_POSTFIELDS => array(
        'username' => 'username',
        'password' => 'myfbpass'
    )
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
// Close request to clear up some resources
curl_close($curl);

Facebook

Of course, Facebook has automatic login detection by using those hidden fields for getting the sessions, but using DOM Document, you can easily get those values and emulate it, at least thats how I was able to simulate login for http://z8games.com/

Good luck

Code Credit: http://codular.com/curl-with-php

Edit:
If you are lazy, you can go ahead and try this page - http://www.daniweb.com/web-development/php/code/290893/facebook-login-with-curl

like image 137
Vlad Avatar answered Nov 09 '22 12:11

Vlad