Downloading current user profile picture

I am wondering, how can i use Facebook api to download user image, that is currently logged in. I don’t have problems with logging in and getting a name of current user, but downloading user picture returns nothing on my android device, as i can’t trace any mistakes on simulator.
So i tried to download both with async method and loadRemoteImage, but I think the main problem is that i can’t get a correct id of user.
 

I tried smth like that

if ( "login" == event.phase ) then facebook.request( "me", "GET" ) end elseif ( "request" == event.type ) then local response = event.response print( response ) end if ( "request" == event.type ) then local response = Json.Decode( event.response ) local data = response.data local function showImage( event ) event.target.alpha = 0 event.target.xScale = 0.25 event.target.yScale = 0.25 transition.to( event.target, { alpha = 1.0 , xScale = 1, yScale = 1} ) end display.loadRemoteImage("http://graph.facebook.com/".. data.id .."/picture", "GET", showImage, "friend"..data.id..".png", system.TemporaryDirectory, math.random(0,display.contentWidth), math.random(0,display.contentHeight) )

Here is what I am using and works fine.

Guess you have to use the username not id.

network.download( "http://graph.facebook.com/" .. me.username .. "/picture?type=square" , "GET", networkListenerFB, picName, system.TemporaryDirectory, 0, 0 )  

Thank you, It works, but i used response.username in my case.
Also i have a small question, i suppose you know the answer. Sometimes me and my testers get a user name ‘Facebook developers’ and blue picture avatar. What solution is the best for this problem?

Sorry, but never came across this problem.

I had a problem to login to facebook with other account then mine. Solved it by removing the app from sandbox mode.

You could also add testers or test group on facebook  app settings page, without removing sandbox mode. That worked fine for me

Here is what I am using and works fine.

Guess you have to use the username not id.

network.download( "http://graph.facebook.com/" .. me.username .. "/picture?type=square" , "GET", networkListenerFB, picName, system.TemporaryDirectory, 0, 0 )  

Thank you, It works, but i used response.username in my case.
Also i have a small question, i suppose you know the answer. Sometimes me and my testers get a user name ‘Facebook developers’ and blue picture avatar. What solution is the best for this problem?

Sorry, but never came across this problem.

I had a problem to login to facebook with other account then mine. Solved it by removing the app from sandbox mode.

You could also add testers or test group on facebook  app settings page, without removing sandbox mode. That worked fine for me

Hello  ubj3d.android,

I’ve used the code you have posted and it works well on my app, by I get poor quality when displaying the downloaded image, How can I get it on a better quality?

Borja

I guess it depends on the size of the picture you have uploaded to the facebook and the size you are displaying in your app.

If the size you are displaying in your app is larger the the one uploaded, then you loose quality.

Well I’ve been thinking about it and actually my profile picture is 720x960 pixels and I’m displaying a square version of it that is 175x175 pixels. That’s why I don’t understand why I loose quality. Thanks for your reply anyway.

Sometimes shrinking a big picture can also loose quality if the shrinking algorithm is bad.

While shrinking, obviously some pixels are being kept, and some are being removed.

Maybe that is causing bad picture quality.

I use Photoshop for shrinking pictures, it does the job very good.

Okay thanks, I’ll give it a look.

can you share your sample code on how to show user facebook photo?

Hello  ubj3d.android,

I’ve used the code you have posted and it works well on my app, by I get poor quality when displaying the downloaded image, How can I get it on a better quality?

Borja

I guess it depends on the size of the picture you have uploaded to the facebook and the size you are displaying in your app.

If the size you are displaying in your app is larger the the one uploaded, then you loose quality.

Well I’ve been thinking about it and actually my profile picture is 720x960 pixels and I’m displaying a square version of it that is 175x175 pixels. That’s why I don’t understand why I loose quality. Thanks for your reply anyway.

Sometimes shrinking a big picture can also loose quality if the shrinking algorithm is bad.

While shrinking, obviously some pixels are being kept, and some are being removed.

Maybe that is causing bad picture quality.

I use Photoshop for shrinking pictures, it does the job very good.

Okay thanks, I’ll give it a look.