Created By Pakainfo.com : Get Faceboook ID

Get User Id from Facebook in PHP

Here is a sort of hack code written by me which allows to fetch any facebook user id even if he is not logged in or authorized by app https://github.com/invisiblevision/get-facebook-id/,I am trying to make a Facebook app and need user id from Facebook when the user opens the applicaiton. I have setup my application and its show mock form on the Facebook canvas, I need help in connecting Facebook API to my page, would i need to download a API for that? And how do I get the user id from the JSON object which facebook says it sends to the application?,A very simple code example to get the user id — if the user is logged in and has authorised the application then $facebook->getUser() will give you the users id:, Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers

A very simple code example to get the user id — if the user is logged in and has authorised the application then $facebook->getUser() will give you the users id:

require 'facebook.php'; $facebook = new Facebook(array( 'appId' => 'YOUR_APP_ID', 'secret' => 'YOUR_APP_SECRET', )); // Get User ID $user = $facebook->getUser(); if ($user) < try < // Get the user profile data you have permission to view $user_profile = $facebook->api('/me'); echo "
"; print_r($user_profile); echo "

"; > catch (FacebookApiException $e) < $user = null; >> else < die(''); >

Answer by Cruz O’Neill

Please go to link to create APP ID and APP SECRET KEY and makea note of it to use in the PHP code.,The following image shows the snapshot for APP ID and APP SECRET KEY.,Writing code in comment? Please use ide.geeksforgeeks.org, generate link and share the link here.,Create new app by clicking Add New App. Enter all the required details like name, email id and click on Create APP ID to get APP ID and APP SECRET to access the Facebook API. You have to change some basic settings to get the desired keys. Refer the image shown below.

Answer by Alessandra Matthews

The app user’s App-Scoped User ID. This ID is unique to the app and cannot be used by other apps.,The person’s significant other,The permissions that the person has granted this app,The advertising accounts the User can access.

GET /v12.0// HTTP/1.1 Host: graph.facebook.com
GET /v12.0// HTTP/1.1 Host: graph.facebook.com
/* PHP SDK v5.0.0 */ /* make the API call */ try < // Returns a `Facebook\FacebookResponse` object $response = $fb->get( '//', '' ); > catch(Facebook\Exceptions\FacebookResponseException $e) < echo 'Graph returned an error: ' . $e->getMessage(); exit; > catch(Facebook\Exceptions\FacebookSDKException $e) < echo 'Facebook SDK returned an error: ' . $e->getMessage(); exit; > $graphNode = $response->getGraphNode(); /* handle the result */
/* PHP SDK v5.0.0 */ /* make the API call */ try < // Returns a `Facebook\FacebookResponse` object $response = $fb->get( '//', '' ); > catch(Facebook\Exceptions\FacebookResponseException $e) < echo 'Graph returned an error: ' . $e->getMessage(); exit; > catch(Facebook\Exceptions\FacebookSDKException $e) < echo 'Facebook SDK returned an error: ' . $e->getMessage(); exit; > $graphNode = $response->getGraphNode(); /* handle the result */
/* make the API call */ FB.api( "//", function (response) < if (response && !response.error) < /* handle the result */ >> );
/* make the API call */ FB.api( "//", function (response) < if (response && !response.error) < /* handle the result */ >> );
/* make the API call */ new GraphRequest( AccessToken.getCurrentAccessToken(), "//", null, HttpMethod.GET, new GraphRequest.Callback() < public void onCompleted(GraphResponse response) < /* handle the result */ >> ).executeAsync();
/* make the API call */ new GraphRequest( AccessToken.getCurrentAccessToken(), "//", null, HttpMethod.GET, new GraphRequest.Callback() < public void onCompleted(GraphResponse response) < /* handle the result */ >> ).executeAsync();
/* make the API call */ FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:@"//" parameters:params HTTPMethod:@"GET"]; [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) < // Handle the result >];
/* make the API call */ FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:@"//" parameters:params HTTPMethod:@"GET"]; [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) < // Handle the result >];
curl -X GET -G \ -d 'access_token=' \ https://graph.facebook.com/v12.0//

Answer by Iker Reilly

Firefox and Microsoft Internet Explorer are recommended browsers for websites using java applets., No Comments @ashwanimishra Follow Recommendations Offline Message ,In the code, the request you sent is made by curl. The token is provided by the facebook. you can get this from the app page on your facebook.,Step3. Create a new function in your controller name it to fb(). Its code will go like this:-

Step3. Create a new function in your controller name it to fb(). Its code will go like this:-

function fb($userid) < $curl = curl_init(); $token = 'YOUR_FB_TOKEN'; // Set some options - we are passing in a useragent too here curl_setopt_array($curl, array( CURLOPT_RETURNTRANSFER =>1, CURLOPT_URL => 'https://graph.facebook.com/'.$userid.'?fields=bio,education,email,gender,hometown,cover,name&access_token='.$token, CURLOPT_USERAGENT => 'snooptravel via curl' )); // Send the request & save response to $resp $resp = curl_exec($curl); $user_fb = json_decode($resp, 1); return $user_fb; >

Step4: To access and use this fb () function you need to call this function and pass the user facebook id. Its code will go like this:-

Now print this $user_fb and the output of the function will be like this;

Array ( [cover] => Array ( [id] => 956276541167528 [offset_y] => 50 [source] => https://scontent.xx.fbcdn.net/v/t1.0-9/13606484_956276541167528_5075420506508913001_n.jpg?oh=2d534af53dd584364fc86bb7c76fb09c&oe=5850BED9 ) [name] => [id] => 100003555744237 )

Answer by Remington Payne

In this Post We Will Explain About is Facebook Api Get User Id Profile Information using PHP With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to how to get user information from facebookExample,In this post we will show you Best way to implement facebook api get user info,facebook get user id, hear for facebook api get user id using PHPwith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck. GET Facebook friends list email mobile profile url using Facebook Graph API ,Manage Facebook Apps with facebook pages using PHP source

 $facebook_username = str_replace('/','',$s_passurl["path"]); //remove any backslash from path $data_results = fb_allget_data('http://graph.facebook.com/'.$facebook_username.'?fields=id,name,picture,locale,gender,username'); if(!empty($data_results->error)) //check if any error is simple returned from facebook < die($data_results->error->message); //all the display error > echo 'Hi '.$data_results->name.', Your Facebook ID is : '.$data_results->id; //everything looks good //display simple all data available echo '
'; print_r($data_results); echo '

'; > function fb_allget_data($json_url) < $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $json_url); $json_data = curl_exec($ch); return json_decode($json_data); curl_close($ch); >?>



//all libs included class require 'php-sdk/src/facebook.php'; $facebook = new Facebook(array( 'appId' => 'put_YOUR_APP_ID', 'secret' => 'put_YOUR_APP_SECRET', )); //simple here store Get User ID $get_user_info = $facebook->getUser(); prtin_r($get_user_info); 

Answer by Micah Larsen

How to log in with Facebook via/using php? It consists of only four steps to login with Facebook PHP SDK:,Download Facebook SDK,Download Facebook SDK.,A: You can use Facebook SDK which is a powerful PHP library built with advanced features for integrating Facebook Login in PHP websites.

Go to the application folder by running the following command

$ cd applications//private_html/

Composer is the recommended method of installing libraries on the platform and I will use it to install Facebook SDK.The first step is the creation of a composer file. In the SSH terminal run composer init command and add the required information to it. It will create a composer.json file in the application folder. Add the following code in composer.json.

Add the following code to profile.php to show the retrieved information. For the purpose of this tutorial, I will retrieve user id, Facebook profile picture, name and email.

Answer by Karter Hendrix

PHP SDK allows accessing the Facebook API from the web application. You can easily implement the Login with Facebook account using Facebook SDK for PHP. This tutorial will show how you can implement user login and registration system with Facebook using PHP and store the user profile data into the MySQL database. Our example Facebook Login script uses Facebook PHP SDK v5 with Facebook Graph API to build Facebook Login system with PHP and MySQL.,The facebook-php-graph-sdk/ directory contains the latest version (v5) of Facebook SDK for PHP. You don’t need to download it separately, all the required files of Facebook PHP SDK v5 are included in our Facebook Login PHP source code.,Once the review process is completed and approved by the Facebook, you will be able to get the user profile link and gender from the Facebook Graph API.,The profile information is retrieved from the Facebook account using Facebook Graph API.

Before you begin to integrate Login with Facebook using PHP, take a look the files structure.

facebook_login_php/ ├── config.php ├── index.php ├── logout.php ├── User.class.php ├── facebook-php-graph-sdk/ ├── images/ │ ├── fb-login-btn.png └── css/ └── style.css 

To store the user’s profile information from Facebook, a table needs to be created in the database. The following SQL creates a users table with some basic fields in the MySQL database to hold the Facebook account information.

CREATE TABLE `users` ( `id` int(11) NOT NULL AUTO_INCREMENT, `oauth_provider` enum('facebook','google','twitter','') COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `oauth_uid` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `first_name` varchar(25) COLLATE utf8_unicode_ci NOT NULL, `last_name` varchar(25) COLLATE utf8_unicode_ci NOT NULL, `email` varchar(25) COLLATE utf8_unicode_ci NOT NULL, `gender` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, `picture` varchar(200) COLLATE utf8_unicode_ci NOT NULL, `link` varchar(100) COLLATE utf8_unicode_ci NOT NULL, `created` datetime NOT NULL, `modified` datetime NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
 // Include the autoloader provided in the SDK require_once __DIR__ . '/facebook-php-graph-sdk/autoload.php'; // Include required libraries use Facebook\Facebook; use Facebook\Exceptions\FacebookResponseException; use Facebook\Exceptions\FacebookSDKException; // Call Facebook API $fb = new Facebook(array( 'app_id' => FB_APP_ID, 'app_secret' => FB_APP_SECRET, 'default_graph_version' => 'v3.2', )); // Get redirect login helper $helper = $fb->getRedirectLoginHelper(); // Try to get access token try < if(isset($_SESSION['facebook_access_token']))< $accessToken = $_SESSION['facebook_access_token']; >else< $accessToken = $helper->getAccessToken(); > > catch(FacebookResponseException $e) < echo 'Graph returned an error: ' . $e->getMessage(); exit; > catch(FacebookSDKException $e) < echo 'Facebook SDK returned an error: ' . $e->getMessage(); exit; >

Источник

Get ID from Facebook PHP SDK

I’ve been sitting all night trying to figure out how to authorize a user via Facebooks API, just to get their User ID. I’ve tried almost all of the tips and ideas from S/O, 5 pages of «Google guides» and the Facebook Developer Guide but nothing seems to work for me! If anyone would be so kind and make a step-by-step guide how to get this to work! Is Open Graph a must for this? I tried it aswell, didn’t work with nor without it. I already have my App (maybe not the right settings there?) and the PHP SDK ( $uid = $facebook->getUser(); etc. not giving me any help at all. ) Thanks in advance! This code for example is not working, I found it here on S/O and he said it was working flawlessly for him!

 '########', 'secret' => '##########################', 'cookie' => true, )); $req_perms = "publish_stream,offline_access,user_status,email,read_stream"; $session = $facebook->getSession(); $loginUrl = $facebook->getLoginUrl(array('canvas'=> 1,'fbconnect' => 0,'req_perms' => $req_perms)); $user_info = null; if (!$session) < echo "";exit;> else< try < $user_info = $facebook->api('/me'); > catch (FacebookApiException $e) < echo ""; exit;> > ?>   "; echo "Hi $user_name ! Your E-mail Address is: ".$user_info['email']."
"; echo "Thanks for accepting our application."; //print_r($user_info); ?>

Edit: Thanks for all the quick responses, I finally got it working! I was on the right track all along.. Step 1 : Make a link like this

https://www.facebook.com/dialog/oauth? client_id=YOUR_APP_ID&redirect_uri=YOUR_URL 

This authorizes the user with the facebook app, which is needed for step2. Step 2 : Implement this code snippet.

require_once('facebook.php'); $fb_app_id = "APP_ID"; $fb_secret = "APP_SECRET"; $fb_app_url = "APP_URL"; $facebook = new Facebook(array( 'appId' => $fb_app_id, 'secret' => $fb_secret, 'cookie' => true, )); $facebook_login_url = $facebook->getLoginUrl(array( 'canvas' => 1, 'fbconnect' => 0, 'scope' => 'publish_stream,user_photos', 'redirect_uri' => $fb_app_url )); $facebook_user_id = $facebook->getUser(); 

Источник

Читайте также:  Java client server database
Оцените статью