In CF10 we had introduced cfoauth tag which helped in social login integration. Lets use it to build a simple facebook app which will download your facebook profile's pic, add some image effects to it and post it to facebook.

1. First we need to ask user to login via facebook so that we can fetch his profile image.

<cfoauth type="facebook" clientid='YOUR_CLIENT_ID'   secretkey="YOUR_SECRET_KEY_HERE"  result="r" scope="" redirecturi="REDIRECT_URL">

 

2. Not lets set this info into some variable 

<cfset Session.fbinfo = #r#>

 

3. Use cfhttp tag to download the image

<cfset thisPath=ExpandPath("*.*")>

<cfset thisDirectory=GetDirectoryFromPath(thisPath)>

<cfhttp method="Get" url="http://graph.facebook.com/#Session.fbinfo.id#/picture?type=large" path="#thisDirectory#" file="final.jpg">

 

4. Now lets use cfimage tage to do various image manipulations 

<cfimage action='resize' height='#height#' width='#width#' source='#thisDirectory#/final.jpg' destination='#thisDirectory#/final.jpg' overwrite=true> 

<cfimage action='rotate' angle='#angle#' source='#thisDirectory#/final.jpg' destination='#thisDirectory#/final.jpg' overwrite=true> 

<cfimage action='border' thickness='#thick#' color='#color#' source='#thisDirectory#/final.jpg' destination='#thisDirectory#/final.jpg' overwrite=true> 


5. Save the image 

<cfimage source="#image#" action="write" destination="#thisDirectory#/final.jpg" overwrite="yes">

6. Lastly post this image to Facebook 

<cfhttp  url="https://graph.facebook.com/me/photos?access_token=#Session.fbinfo.access_token#" method="post" multipart="yes">
   <cfhttpparam type="file" name="source" file="#thisDirectory#\final.jpg">
</cfhttp>


 


 

2 Comments to “Creating a simple facebook app which manipulates your profile pic”

  1. Tom Chiverton
    Once again, could really have done with being proof read, for the prose and the code.
    From just the first two parts:

    "CF10 we had introduced" - "CF10 we have introduced"

    "<cfset Session.fbinfo = #r#>" - "<cfset Session.fbinfo = r>"

    I stopped reading there because then you started using ' instead of " for the tags, never mind you should use script for writing service code like this.
  2. Adam
    Interesting stuff, I haven't used the cfoauth tag yet I'll have to give it a shot. Thank you for the example

Leave a Comment

Leave this field empty: