download facebook profile pictures of your friends ?

Hi i was wondering if there is a simple way of downloading my facebook friends   profile pictures and save them to the local game folder so i can use them in a game ? 

-kevin

Not going to post the exact code, but the steps you need to follow are:

Log-in to Facebook with the correct permissions 

Make a Request for Friends

Facebook will send back a JSON object containing all of this data - I can’t remember exactly what the image is stored as, but if you print out the object you’ll be able to determine what you need to look for.

Decode the JSON object to a Lua Table

Loop through the table, storing the images.

Something like that should get you started.

EDIT

Cublah has just jogged my memory - as he states you need to download the image using the correct path and FBID.

This is what I use for getting a Facebook picture once you have the users Facebook id (fbid) it checks to see if the file exists already so you don’t get duplicate downloads. Bear in mind though I had one user complain that the app crashed on their phone, although upon investigation they did have over 5000 Facebook friends!!!

local function imageDLListener ( event )

    if ( event.isError ) then

        print ( “Network error - download failed” )

    end

end

function loadImage(fbid)

    – Create local file for saving data

    local path = system.pathForFile( “pic”…fbid…".png", system.TemporaryDirectory )

    local fh, errStr = io.open( path, “r” )

    if fh then

        print("### found file ###")

        io.close(fh)

        return

    end

    – Request remote file and save data to local file

    print(“http://graph.facebook.com/”…fbid…"/picture?type=normal")

    network.download( 

        “http://graph.facebook.com/”…fbid…"/picture?type=normal", 

        “GET”, 

        imageDLListener, 

        “pic”…fbid…".png", 

        system.TemporaryDirectory )

end

Have a look at this tutorial, it should have a lot of what you need to do.

http://mobile.tutsplus.com/tutorials/corona/corona-sdk-working-with-the-facebook-graph-api-part-2/

thanks for the tips!

Not going to post the exact code, but the steps you need to follow are:

Log-in to Facebook with the correct permissions 

Make a Request for Friends

Facebook will send back a JSON object containing all of this data - I can’t remember exactly what the image is stored as, but if you print out the object you’ll be able to determine what you need to look for.

Decode the JSON object to a Lua Table

Loop through the table, storing the images.

Something like that should get you started.

EDIT

Cublah has just jogged my memory - as he states you need to download the image using the correct path and FBID.

This is what I use for getting a Facebook picture once you have the users Facebook id (fbid) it checks to see if the file exists already so you don’t get duplicate downloads. Bear in mind though I had one user complain that the app crashed on their phone, although upon investigation they did have over 5000 Facebook friends!!!

local function imageDLListener ( event )

    if ( event.isError ) then

        print ( “Network error - download failed” )

    end

end

function loadImage(fbid)

    – Create local file for saving data

    local path = system.pathForFile( “pic”…fbid…".png", system.TemporaryDirectory )

    local fh, errStr = io.open( path, “r” )

    if fh then

        print("### found file ###")

        io.close(fh)

        return

    end

    – Request remote file and save data to local file

    print(“http://graph.facebook.com/”…fbid…"/picture?type=normal")

    network.download( 

        “http://graph.facebook.com/”…fbid…"/picture?type=normal", 

        “GET”, 

        imageDLListener, 

        “pic”…fbid…".png", 

        system.TemporaryDirectory )

end

Have a look at this tutorial, it should have a lot of what you need to do.

http://mobile.tutsplus.com/tutorials/corona/corona-sdk-working-with-the-facebook-graph-api-part-2/

thanks for the tips!