Corona/Facebook conundrum

I’m working on a piece of an app that will allow a user to choose multiple friends from a list and move on from there (what they’ll do isn’t important, nor is it entirely determined at this point).

I have no problem going through the SSO and Json decoding the data return once they OK my FB app, but need to pull in thumbnail images and have them associated with the correct user ID. Seems simple enough. The code I’m using to pull in images looks like this:
[lua] local function showImage( event )
scrollView:insert(event.target)
scrollView:addFBImage(event.target)
end

for i=1,#data do
display.loadRemoteImage(“http://graph.facebook.com/”… data[i].id …"/picture",
“GET”,
showImage,
“friend”…i…".png",
system.TemporaryDirectory )
if i == table.maxn(data) then
print("iteration finished at " … i)
scrollView:setFriendsLength(i)
end

end[/lua]
The showImage callback works like a charm, lays them all out and inserts them into a scrollView. However, the callback doesn’t allow me to associate the user ID with that particular image (no parameters allowed), and I gather through print/trace experiments that it’s possible for the callbacks to be called out of order (in other words, I can’t make a parallel table with user ID’s and be sure they will match up 1:1). I may be wrong about that last part but would rather be safe than sorry.

Is there a better way to do this?
Thanks in advance.
Danny [import]uid: 103470 topic_id: 27835 reply_id: 327835[/import]

Wonder if you can access the file name from the display object? Then you could parse the name out. This is a fundamental problem. Maybe you could put in a feature request to have the id of the request end up in the event table or something.

You can look through the contributed code for the print_r function or other table dumpers and dump the event.target table and see if there is anything useful there that you can use.
[import]uid: 19626 topic_id: 27835 reply_id: 112691[/import]

Rob, thanks for your response.
Not sure if we’re talking about the same thing, but I tried:
[lua]local tmp = display.loadRemoteImage(“http://graph.facebook.com/”… data[i].id …"/picture",
“GET”,
showImage,
“friend”…i…".png",
system.TemporaryDirectory )
print(tmp)[/lua]

and got a result of “nil” - if I’d been able to get the anonymous ‘table’ assignment of the display object, that would have been good enough to pair it up with the id I think. Seems the object itself gets created *after* download, not before.
I also looked for a way to access a “name” property or even some kind of source-file-name reference thinking I could associate it with the “friend99.png” file name, but there’s nothing like that documented (I spent a lot of time doing actionscript, so name is a familiar crutch)

print_r looks like a cool trick. I didn’t know about that. I’ll check it out.

I’m thinking my best bet, though it’s more verbose and possibly ‘heavier’ on memory, is to consciously create an empty display object for each one, associate that with the user id in a table, then inject the loadRemoteImage into my pre-created display object. Feels like a hack but at this point I’d like to move on to the next step.

As for a feature request, I think being able to add a custom table parameter to the call back would solve everything… [import]uid: 103470 topic_id: 27835 reply_id: 112694[/import]

Naw, we are on the same page. display.loadRemoteImage() doesn’t return anything. It will always be nil, however in your call back function, event.target IS the display object which is why you can insert it into your view.

Dump that table/object out and see if there is anything useful in it, like the filename since you are putting the ID in the file name.

[import]uid: 19626 topic_id: 27835 reply_id: 112696[/import]

Bingo.
That print_r function may wind up paying for itself.
It’s still not an ideal solution but won’t require that I overhaul the code to, as I say, move on to the next step.

[lua] local function showImage( event )
scrollView:insert(event.target)
print_r(event)
print("--------")
print(event.url)
print("------------")
scrollView:addFBImage(event.target)
end[/lua]
gets me:

 table: 0x69870e0 {  
 [name] =\> "networkRequest"  
 [target] =\> table: 0x69870e0 {  
 [\_class] =\> table: 0x69ead60 {  
 [removeEventListener] =\> function: 0x69394b0  
 [initProxy] =\> function: 0x6929a10  
 [addEventListener] =\> function: 0x69394d0  
 [\_\_index] =\> table: 0x6929c50 {  
 \*table: 0x6929c50  
 }  
 }  
 [\_proxy] =\> userdata: 0x69eaae4  
 }  
 [status] =\> 200  
 [url] =\> "/var/folders/Mr/MrBVT4LDFq4Fd3JqYbQPJE+++TM/-Tmp-/friend83.png"  
 [isError] =\> false  
 [response] =\> "/var/folders/Mr/MrBVT4LDFq4Fd3JqYbQPJE+++TM/-Tmp-/friend83.png"  
 }  
 --------  
 /var/folders/Mr/MrBVT4LDFq4Fd3JqYbQPJE+++TM/-Tmp-/friend83.png  
 ------------  

(added the url trace after the first print_r output to be sure that was the way I’d access it)
I’ve still got to yank that filename (or just number) from the rest of it, but I can deal with that.
Thank you [import]uid: 103470 topic_id: 27835 reply_id: 112703[/import]

Yea, the print_r function has saved me a lot!

I would suggest maybe putting some underscores in the filename around the ID number to make it easier to parse it out. [import]uid: 19626 topic_id: 27835 reply_id: 112706[/import]