The new graphapi makes getting Facebook connect super easy, but putting all the pieces together is a little tough.
What you need to do is set-up the Facebook connect button, and let it save the cookies for you. From there you can get an access token, required to get information back from the API. You can use cfhttp calls and get JSON back.
Step one is to follow Facebook’s instructions to get the Javascript set-up for the Facebook Connect button, found here:
https://developers.facebook.com/docs/guides/web/#login
Note: You need to request the permissions that you want in the button HTML, for example ours looks like this:
<fb:login-button perms="email, user_education_history, friends_education_history, publish_stream, offline_access">
Once this is done, you can use some ColdFusion to read the cookie and get the accesstoken.
<cfset left = Find("access_token=",cookie.fbs_239625941285)+13>
<cfset right = Find("&",cookie.fbs_239625941285,left+1)>
<cfset accessToken = Mid(cookie.fbs_239625941285,left,right-left)>
<cfoutput>Access Token = #accessToken#</cfoutput>
And to get the Facebook ID:
cfset left = Find("&uid=",cookie.fbs_239625941285)+5>
<cfset len = len(cookie.fbs_239625941285)-left>
<cfset SESSION.FBID = mid(cookie.fbs_239625941285,left,len)>
<br><cfoutput>Facebook ID = #SESSION.FBID#</cfoutput>
The next thing is to use the Graph Explorer tool to find the syntax for what you want to pull:
https://developers.facebook.com/tools/explorer
For example to get e-mail we use the code:
<cfdump var="#cookie#"> <cfhttp url="https://graph.facebook.com/100000929135466/?#accessToken#" method="get" /> <cfset response = DeserializeJSON(cfhttp.filecontent) /> <cfoutput> <p>email = #response.email#</p> </cfoutput>
You can try an example here:
And I have uploaded the CFM files here:
http://webapps.roanoke.edu/michael/fbconnect/facebookconnect.zip
Let me know if you have questions or comments!
{ 1 comment }