retriving a user's facebook picture using facebook connect

hi
does anyone here has a script for retriving a user facebook picture just after he connects to facebook with an app ?
(and then maybe save this picture in a veriable ? )

(i mean a script to retrive a user facebook AFTER he connected (assuming you don’t know who the user is in ahead)

[import]uid: 174056 topic_id: 32422 reply_id: 332422[/import]

@oripost, I use something like the following in my latest project to show the FB pix. You may want to consider using system.CachesDirectory instead of system.TemporaryDirectory (which I’m considering and looking into at I write this.) Also, you probably want to scale the size of the images based on what you display (to accomodate different device resolution.)

Anyhow, hope this helps.

Naomi

-- profile image 100 pixels wide, variable height  
display.loadRemoteImage( "http://graph.facebook.com/".. FB\_ID .."/picture?type=normal", "GET", showImage,"friend"..FB\_ID..".png", system.TemporaryDirectory, 0, 0 );  
  
-- profile image about 200 pixels wide, variable height  
display.loadRemoteImage( "http://graph.facebook.com/".. FB\_ID .."/picture?type=large", "GET", showImage,"friend"..FB\_ID..".png", system.TemporaryDirectory, 0, 0 );  

P.S. Woops, not sure what you mean by “retrive a user facebook AFTER he connected (assuming you don’t know who the user is in ahead).” By the time you retrieve user faceboook ID, you’d know the FB ID, wouldn’t you? [import]uid: 67217 topic_id: 32422 reply_id: 129009[/import]

hi…
the quastion is how do i get the users, FB_ID ?
do you have a complete code for that ?
i tried everything and nevermind what i tried i can’t retrive the user’s ID …

thank you sooo much … [import]uid: 174056 topic_id: 32422 reply_id: 129037[/import]

@oripost, I use something like the following in my latest project to show the FB pix. You may want to consider using system.CachesDirectory instead of system.TemporaryDirectory (which I’m considering and looking into at I write this.) Also, you probably want to scale the size of the images based on what you display (to accomodate different device resolution.)

Anyhow, hope this helps.

Naomi

-- profile image 100 pixels wide, variable height  
display.loadRemoteImage( "http://graph.facebook.com/".. FB\_ID .."/picture?type=normal", "GET", showImage,"friend"..FB\_ID..".png", system.TemporaryDirectory, 0, 0 );  
  
-- profile image about 200 pixels wide, variable height  
display.loadRemoteImage( "http://graph.facebook.com/".. FB\_ID .."/picture?type=large", "GET", showImage,"friend"..FB\_ID..".png", system.TemporaryDirectory, 0, 0 );  

P.S. Woops, not sure what you mean by “retrive a user facebook AFTER he connected (assuming you don’t know who the user is in ahead).” By the time you retrieve user faceboook ID, you’d know the FB ID, wouldn’t you? [import]uid: 67217 topic_id: 32422 reply_id: 129009[/import]

@oripost, my code is too involved with what I am doing with my project that I don’t think I can quickly condense it down to a state that would be good to post on Forum. You might want to take a look at the following blog post, though. It’s what helped me work out FB basics. (Fetching the JSON object is the key here. It gives you what you need. Make sure to use print statement to see what JSON object contains. The rest should be a smooth ride.)

http://www.coronalabs.com/blog/2010/11/04/api-teaser-graph-requests-in-facebook/

Naomi [import]uid: 67217 topic_id: 32422 reply_id: 129101[/import]

hi…
the quastion is how do i get the users, FB_ID ?
do you have a complete code for that ?
i tried everything and nevermind what i tried i can’t retrive the user’s ID …

thank you sooo much … [import]uid: 174056 topic_id: 32422 reply_id: 129037[/import]

@oripost, my code is too involved with what I am doing with my project that I don’t think I can quickly condense it down to a state that would be good to post on Forum. You might want to take a look at the following blog post, though. It’s what helped me work out FB basics. (Fetching the JSON object is the key here. It gives you what you need. Make sure to use print statement to see what JSON object contains. The rest should be a smooth ride.)

http://www.coronalabs.com/blog/2010/11/04/api-teaser-graph-requests-in-facebook/

Naomi [import]uid: 67217 topic_id: 32422 reply_id: 129101[/import]

Hey Naomi…
first of all thank you soo much … your a reall sweetheart,
the thing is how can you see a print command on the iphone ?
becouse on the corona simulator the facebook doesn’t work… and in the corona terminal is the only way i know of reading a print line…
when i try the code from your link for myself it says an ERROR on the lne

local tableView = require(“tableView”)

but even when i kinda… fix it…look
HERE is MY code…
(everytime i try to print the TESTIT it just doesn’t write anything…)
so … i mean …
pls ? can you give me a ready code that publishes a facebook picture ? please ?

local facebook = require “facebook”
local json = require “json”
local tableView = require(“tableView”)
– listener for “fbconnect” events
local function listener( event )
if ( “session” == event.type ) then
– upon successful login, request list of friends
if ( “login” == event.phase ) then
facebook.request( “me/friends” )
end
elseif ( “request” == event.type ) then
– event.response is a JSON object from the FB server
local response = event.response
print ( response )

– if request succeeds, create a scrolling list of friend names
if ( not event.isError ) then

response = json.decode( event.response )

TESTIT = display.newText (response, 150, 200, nil, 30)

local friends = {}
local data = response.data
for i=1,#data do
local name = data[i].name
table.insert( friends, name )
end

local topBoundary = display.screenOriginY + 40
local bottomBoundary = display.screenOriginY + 0

– create the list of items
myList = tableView.newList{
data=friends,
default=“listItemBg.png”, over=“listItemBg_over.png”,
top=topBoundary, bottom=bottomBoundary,
}
end
elseif ( “dialog” == event.type ) then
print( “dialog”, event.response )
end
end

– first argument is the app id that you get from Facebook
facebook.login( “314542735310401”, listener )

thank you sooo much for helping me on this…it is realllly important to me . and i’m kinda stuck on that…
[import]uid: 174056 topic_id: 32422 reply_id: 129204[/import]

Hi there,

You need to have your iDevice connected to your Mac while using it, and within xcode there should be an option to view the console output for your device in the organizer I believe. [import]uid: 62706 topic_id: 32422 reply_id: 129212[/import]

thank you …
do you know though how to make it work ? with the facebook picture ?
do you have a code that works to retrive a facebook pic ? PLS ?
[import]uid: 174056 topic_id: 32422 reply_id: 129214[/import]

Never tried this I am afraid.

Is the error with local tableView = require(“tableView”)?

Where did you learn this, as it may be an old way of doing things.

Check this document for tableviews:
http://docs.coronalabs.com/api/library/widget/newTableView.html [import]uid: 62706 topic_id: 32422 reply_id: 129216[/import]

even if i go beyond and fix the table view…
i still can’t decode the facebook data properly … and get a uder ID from it…
do you have a code that can get me a User ID ?
becouse i can’t get it …never mind what i do … [import]uid: 174056 topic_id: 32422 reply_id: 129218[/import]

Actually…

the Graph API call: “me/friends” can delivery you a table member called “picture” along with their name, username, userID, is your app installed, etc.

that member is either a table with a URL member or it’s just a string that contains the URL to their picture.

Feed that URL to network.download() or display.loadRemoteImage() and you’re good to go. This gets a 50x50 image. Naomi’s version may get to the larger picture.

I’m also using LFS to look in the caches directory to see if I have the image and make sure its not too old before I re-download it. [import]uid: 19626 topic_id: 32422 reply_id: 129228[/import]

I think I like Naomi’s URL’s better since I can get bigger pictures!
[import]uid: 19626 topic_id: 32422 reply_id: 129229[/import]

thnx, the thing is i tried it soo manny times…
can you PLEASE give me a code that works ? that can get me that picture ? or even the user ID ? PLS ?
i just need the syntex… i mean the code …
Please ???
[import]uid: 174056 topic_id: 32422 reply_id: 129230[/import]

local json = require("json")  
local friends  
  
local function listener( event )  
 if ( "session" == event.type ) then  
 -- upon successful login, request list of friends  
 if ( "login" == event.phase ) then  
 facebook.request( "me/friends", "GET" )  
 end  
 elseif ( "request" == event.type ) then  
 -- event.response is a JSON object from the FB server  
 local response = event.response  
 print( response )  
 friends = json.decode(event.response)  
 for i = 1, #friends do  
 print(friends[i].name, friends[i].id)  
 end  
 end  
end  
facebook.login( "1234567890", listener, {"publish\_stream"} )  

where “1234567890” is your app ID.

In side the listener function for the elseif event.type == "request bit you end up with a big table of all your friends. Do with it what you want. [import]uid: 19626 topic_id: 32422 reply_id: 129238[/import]

Hey Naomi…
first of all thank you soo much … your a reall sweetheart,
the thing is how can you see a print command on the iphone ?
becouse on the corona simulator the facebook doesn’t work… and in the corona terminal is the only way i know of reading a print line…
when i try the code from your link for myself it says an ERROR on the lne

local tableView = require(“tableView”)

but even when i kinda… fix it…look
HERE is MY code…
(everytime i try to print the TESTIT it just doesn’t write anything…)
so … i mean …
pls ? can you give me a ready code that publishes a facebook picture ? please ?

local facebook = require “facebook”
local json = require “json”
local tableView = require(“tableView”)
– listener for “fbconnect” events
local function listener( event )
if ( “session” == event.type ) then
– upon successful login, request list of friends
if ( “login” == event.phase ) then
facebook.request( “me/friends” )
end
elseif ( “request” == event.type ) then
– event.response is a JSON object from the FB server
local response = event.response
print ( response )

– if request succeeds, create a scrolling list of friend names
if ( not event.isError ) then

response = json.decode( event.response )

TESTIT = display.newText (response, 150, 200, nil, 30)

local friends = {}
local data = response.data
for i=1,#data do
local name = data[i].name
table.insert( friends, name )
end

local topBoundary = display.screenOriginY + 40
local bottomBoundary = display.screenOriginY + 0

– create the list of items
myList = tableView.newList{
data=friends,
default=“listItemBg.png”, over=“listItemBg_over.png”,
top=topBoundary, bottom=bottomBoundary,
}
end
elseif ( “dialog” == event.type ) then
print( “dialog”, event.response )
end
end

– first argument is the app id that you get from Facebook
facebook.login( “314542735310401”, listener )

thank you sooo much for helping me on this…it is realllly important to me . and i’m kinda stuck on that…
[import]uid: 174056 topic_id: 32422 reply_id: 129204[/import]

Hi there,

You need to have your iDevice connected to your Mac while using it, and within xcode there should be an option to view the console output for your device in the organizer I believe. [import]uid: 62706 topic_id: 32422 reply_id: 129212[/import]

thank you …
do you know though how to make it work ? with the facebook picture ?
do you have a code that works to retrive a facebook pic ? PLS ?
[import]uid: 174056 topic_id: 32422 reply_id: 129214[/import]

Never tried this I am afraid.

Is the error with local tableView = require(“tableView”)?

Where did you learn this, as it may be an old way of doing things.

Check this document for tableviews:
http://docs.coronalabs.com/api/library/widget/newTableView.html [import]uid: 62706 topic_id: 32422 reply_id: 129216[/import]