|
||||||||||||||||||||||||||||||||||||||||
Facebook: Getting User Social Data +++Currently this is implemented in Facebook in their "Graph API". You can access to much of this data given the basic information user authentication has been performed and you have an OAuth token for a user.
First, some basic concepts..... SOCIAL Graph =
How to access a Node in the graphOPTION 1 - with ID
OPTION 2: Use name (for people and pages)
|
{ "id": "220439", "name": "Bret Taylor", "first_name": "Bret", "last_name": "Taylor", "link": "http://www.facebook.com/btaylor", "username": "btaylor", "hometown": { "id": "108363292521622", "name": "Oakland, California" }, "location": { "id": "109650795719651", "name": "Los Gatos, California" }, "work": [ { "employer": { "id": "20531316728", "name": "Facebook" }, "position": { "id": "148305368513781", "name": "CTO" }, "with": [ { "id": "4", "name": "Mark Zuckerberg" }, { "id": "1586010043", "name": "Zach Rait" } ], "start_date": "2009-08", "end_date": "0000-00", "projects": [ { "id": "153823678006564", "name": "Open Graph", "with": [ { "id": "4", "name": "Mark Zuckerberg" } ], "from": { "id": "4", "name": "Mark Zuckerberg" } } ] }, { "employer": { "id": "99073561945", "name": "FriendFeed" }, "location": { "id": "108212625870265", "name": "Mountain View, California" }, "position": { "id": "116320241753504", "name": "Founder & CEO" }, "with": [ { "id": "581903346", "name": "Goutham Patnaik" }, { "id": "15500414", "name": "Benjamin Golub" }, { "id": "223020", "name": "Tudor Bosman" }, { "id": "1214835", "name": "Dan Hsiao" }, { "id": "836701", "name": "Casey Maloney Rosales Muller" }, { "id": "4809535", "name": "Kevin Fox" }, { "id": "500039935", "name": "Gary Burd" }, { "id": "207830", "name": "James Norris" }, { "id": "580246416", "name": "Sanjeev Singh" }, { "id": "672745547", "name": "Paul Buchheit" } ], "start_date": "2007-10", "end_date": "2009-08" }, { "employer": { "id": "86860316161", "name": "Benchmark Capital" }, "location": { "id": "104048449631599", "name": "Menlo Park, California" }, "position": { "id": "104098916294662", "name": "Entrepreneur In Residence" }, "with": [ { "id": "210560", "name": "Peter Fenton" }, { "id": "207830", "name": "James Norris" } ], "start_date": "2007-06", "end_date": "2007-09" }, { "employer": { "id": "104958162837", "name": "Google" }, "position": { "id": "103146903077097", "name": "Group Product Manager" }, "start_date": "2003-03", "end_date": "2007-06", "projects": [ { "id": "162849873739882", "name": "Google Maps", "with": [ { "id": "207830", "name": "James Norris" }, { "id": "767560056", "name": "Lars Eilstrup Rasmussen" }, { "id": "734236612", "name": "Jens E. Rasmussen" } ] } ] } ], "favorite_teams": [ { "id": "112437965439134", "name": "Stanford Cardinal" }, { "id": "106533819377582", "name": "San Francisco 49ers" }, { "id": "109892325707088", "name": "A's" } ], "favorite_athletes": [ { "id": "106056612759445", "name": "Toby Gerhart" }, { "id": "112417838771364", "name": "Joe Montana" }, { "id": "132355330134939", "name": "Andrew Luck" } ], "inspirational_people": [ { "id": "103864656318694", "name": "Linus Torvalds" }, { "id": "113529011990795", "name": "Steve Jobs" } ], "education": [ { "school": { "id": "112075895485567", "name": "Acalanes High" }, "type": "High School" }, { "school": { "id": "6192688417", "name": "Stanford University" }, "concentration": [ { "id": "192578844099494", "name": "Computer Science" } ], "type": "College" }, { "school": { "id": "6192688417", "name": "Stanford University" }, "degree": { "id": "193640483997198", "name": "MS" }, "concentration": [ { "id": "192578844099494", "name": "Computer Science" } ], "type": "Graduate School" } ], "gender": "male", "locale": "en_US", "languages": [ { "id": "106059522759137", "name": "English" }, { "id": "110343528993409", "name": "Spanish" } ], "updated_time": "2011-05-02T05:06:10+0000" } |
PHP example
https://graph.facebook.com/220439?access_token=...
<?php $app_id = YOUR_APP_ID; //this you need to change $app_secret = YOUR_APP_SECRET; //this you need to change $access_token = THE_ACCESS_TOKEN //this you get after you have done authentication $user_id = THE_USER_ID; //this you get after you have done authentication //AUTHENTICATION MUST BE DONE FIRST //see previous code samples............here is an example $app_id = "YOUR_APP_ID"; $canvas_page = "YOUR_CANVAS_PAGE_URL";
$auth_url = "http://www.facebook.com/dialog/oauth?client_id=". $app_id . "&redirect_uri=" . urlencode($canvas_page);
$signed_request = $_REQUEST["signed_request"]; // this will be passed automatically (see above) to
// your app when user invokes
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
if (empty($data["user_id"])) { // if no data given about user in signed_request info then ask user // to authorize your app to get it
// facebook will return to the canvas_page as a "call back " url //and pass the new signed_request echo("<script> top.location.href='" . $auth_url . "'</script>"); } else { $access_token = $data["oauth_token"]; //grab the oauth token sent } //ASK FOR INFORMATION ABOUT USER (assumes authentication successful) $user_getinfo_url = "https://graph.facebook.com/".$user_id . "access_token?" .$access_token $user_data = file_get_contents($user_getinfo_url); echo("User Data recieved:", $user_data); //process $user_data as you need....more code here!!! ?>
You can publish to the Facebook graph by issuing HTTP POST requests to the appropriate connection URLs, using an access token.
For example, you can post a new wall post on Arjun's wall by issuing a POST request to https://graph.facebook.com/arjun/feed
in PHP using curl library
curl -F 'access_token=...' \
-F 'message=Hello, Arjun. I like this new API.' \
https://graph.facebook.com/arjun/feed
Most write operations require extended permissions for the active user. See the authentication guide for details on how you can request extended permissions from the user during the authentication step.
We support writing the following types of objects:
Method |
Description |
Arguments |
/PROFILE_ID/feed |
Publish a new post on the given profile's feed/wall |
message, picture, link, name, caption, description, source |
/OBJECT_ID/comments |
Comment on the given object (if it has a /comments connection) |
message |
/OBJECT_ID/likes |
Like the given object (if it has a /likes connection) |
none |
/PROFILE_ID/notes |
Publish a note on the given profile |
message, subject |
/PROFILE_ID/links |
Publish a link on the given profile |
link, message, picture, name, caption, description |
/PROFILE_ID/events |
Create an event |
name, start_time, end_time |
/EVENT_ID/attending |
RSVP "attending" to the given event |
none |
/EVENT_ID/maybe |
RSVP "maybe" to the given event |
none |
/EVENT_ID/declined |
RSVP "declined" to the given event |
none |
/PROFILE_ID/albums |
Create an album |
name, message |
/ALBUM_ID/photos |
message, source (multipart/form-data) |
|
/PROFILE_ID/checkins |
coordinates, p |