简体   繁体   中英

Facebook: Get user's Facebook UID with PHP

I had found the way to print the user ID, photo and name. And other type of info easily with PHP but I didn't save the link and can't find how to do it.

I only want to know what's the simplest method to get the User's ID. I need to save it to my database in here:

<?php
// Get new icon
mysql_select_db("cyberworlddb", $con);

mysql_query("INSERT IGNORE INTO Badges (UID, Website, Code)
VALUES ('UID','$urlhost[0]','1$urlhost[0]')");
?>

How can I do it?

If they are logged into your Facebook application you can get their session token from the facebook cookie (http://developers.facebook.com/docs/authentication/) and then you just use the graph api:

$me = json_decode(@file_get_contents('https://graph.facebook.com/me?access_token=' . $cookie['access_token']));

$uid = $me->id;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM