Facebook hat jetzt ne Graph API, das bedeutet die Kommunikation wird noch einfacher.
Will man beispielsweise Daten eines Users abrufen, kann man einfach mal diesen Befehl in den Browser eingeben:
https://graph.facebook.com/$userid?metadata=1$userid mit was Sinnlosem ersetzen, beispielsweise https://graph.facebook.com/fdpdvp, und es kommt zurück:
{
"id": "100000085198858",
"name": "Fdp-dvp Fraktion",
"first_name": "Fdp-dvp",
"last_name": "Fraktion",
"link": "http://www.facebook.com/fdpdvp"
}Hängt man dann noch ein
metadata=1an, kommen weitere Funktionen zu Tage:
https://graph.facebook.com/fdpdvp?metadata=1
{
"id": "100000085198858",
"name": "Fdp-dvp Fraktion",
"first_name": "Fdp-dvp",
"last_name": "Fraktion",
"link": "http://www.facebook.com/fdpdvp",
"metadata": {
"connections": {
"home": "https://graph.facebook.com/fdpdvp/home",
"feed": "https://graph.facebook.com/fdpdvp/feed",
"friends": "https://graph.facebook.com/fdpdvp/friends",
"family": "https://graph.facebook.com/fdpdvp/family",
"activities": "https://graph.facebook.com/fdpdvp/activities",
"interests": "https://graph.facebook.com/fdpdvp/interests",
"music": "https://graph.facebook.com/fdpdvp/music",
"books": "https://graph.facebook.com/fdpdvp/books",
"movies": "https://graph.facebook.com/fdpdvp/movies",
"television": "https://graph.facebook.com/fdpdvp/television",
"likes": "https://graph.facebook.com/fdpdvp/likes",
"posts": "https://graph.facebook.com/fdpdvp/posts",
"tagged": "https://graph.facebook.com/fdpdvp/tagged",
"statuses": "https://graph.facebook.com/fdpdvp/statuses",
"links": "https://graph.facebook.com/fdpdvp/links",
"notes": "https://graph.facebook.com/fdpdvp/notes",
"photos": "https://graph.facebook.com/fdpdvp/photos",
"albums": "https://graph.facebook.com/fdpdvp/albums",
"events": "https://graph.facebook.com/fdpdvp/events",
"groups": "https://graph.facebook.com/fdpdvp/groups",
"videos": "https://graph.facebook.com/fdpdvp/videos",
"picture": "https://graph.facebook.com/fdpdvp/picture",
"inbox": "https://graph.facebook.com/fdpdvp/inbox",
"outbox": "https://graph.facebook.com/fdpdvp/outbox",
"updates": "https://graph.facebook.com/fdpdvp/updates"
}
},
"type": "user"
}Wie die Authorisierung funktioniert steht hier, Code Samples in PHP und Python anbei.
Auf jeden Fall braucht man eine Registrierung von Facebook, die einem eine
$client_idund ein
$client_secretzu Verfügung stellt.
Wenn man nun einen Besucher mit Facebook verbinden will, baut man folgende URL in einen Link ein:
https://graph.facebook.com/oauth/authorize?
client_id=...&
redirect_uri=http://www.example.com/oauth_redirectDarauf hin bekommt der Besucher den Facebook-Login zu sehen, loggt sich ein, und wird von Facebook zurück auf die
$redirect_urigeschickt, mit angehängtem Verifizierungsschlüssel sieht das dann so aus:
http://www.example.com/oauth_redirect?code=VERIFIZIERUNGSBLABLUBBDen Verifizierungsschlüssel tauscht man dann gegen ein Access Token um, dazu muss neben der Client ID nun auch noch das Client Secret übergeben werden, und die exakt gleiche redirect_uri wie eben:
https://graph.facebook.com/oauth/access_token?
client_id=...&
redirect_uri=http://www.example.com/oauth_redirect&
client_secret=...&
code=...Für den Verifizierungsschlüssel bekommen wir ein Access Token, das wir dann nutzen können, um überhaupt die User ID des Besuchers herausfinden zu können.
