question about photos.getSizes()

16 views
Skip to first unread message

goodlux

unread,
Apr 11, 2009, 10:15:33 AM4/11/09
to ActionScript 3 Flickr Library
Hi -

I'm trying to write some code that displays photos from a photoset in
a a slideshow. Pretty basic stuff here.

I've gotten as far as getting the the Photoset with all of the
Photos...then I'm trying to run service.photos.getSizes.

However, there seems to be a problem with the implementation here.

Basically I want to loop through all the photos in a set, and call
getSizes for each photo. Another function works as an event listener,
waiting for the response from the service.

I'd like to match the urls returned from getSizes with the photo that
was specified in the getSizes() parameters. There doesn't seem to be a
way to do this. The response from getSizes doesn't include the photo
id...except in the urls. Do I have to parse the URLs to get the photo
id out? There must be a more straightforward way to do this?

Thanks!


ja...@bangersandflash.net

unread,
Apr 14, 2009, 8:09:46 PM4/14/09
to ActionScript 3 Flickr Library
Hi,
I was having problems with this too, and apart from incrementing the
for loop only once a photoSizes method has returned something (slow if
you have a lot of photos) the best way I've found to grab the photo
urls is to build them up manually.

The url for the photos is built up like this
"http://static.flickr.com/" + the photo's server + "/" + the photo's
ID (or photoset's primaryPhotoID + "_" + the photo's secret + the size
of the photo + ".jpg"));

You can access your own photos to work out the photosizes but they're
something along the lines of:
"_s" - square thumbnail
"_t" - thumbnail
"_m" - medium
"_o" - original
or you can leave it blank for the default size. (you might want to
double check these)

With that in mind, you just need to build up the path to the photo,
and make sure you add the correct parameter on the end of it to grab
that size:
var p:Photo = new Photo();
var squareUrl:String = "http://static.flickr.com/" + p.server + "/" +
p.id + "_" + p.secret + "_s.jpg"));

So if you were pulling the photos from a set it'd look something like
this:

FlickrService.addEventListener(FlickrResultEvent.PHOTOSETS_GET_PHOTOS,
loadPhotos);
FlickrService.photosets.getPhotos(/*pass a photoset id here*/);
private function loadPhotos(e:FlickrResultEvent):void {
var setPhotos:Array = e.data.photoSet.photos as Array;
for(var i:uint = 0; i < setPhotos.length; i ++){
var p:Photo = setPhotos[i] as Photo;
var squareUrl:String = "http://static.flickr.com/" + p.server + "/"
+ p.id + "_" + p.secret + "_s.jpg"));
trace(squareUrl)
}
}

I hope that helps you out a bit. Just yell out if you have any more
problems with it ;)

Cheers,
Jassa

landed

unread,
May 21, 2009, 1:28:35 PM5/21/09
to ActionScript 3 Flickr Library
Hi guys. I have been struggling for a while with similar. Essentially
the summary is that the events that get returned from the api have no
id info with them, so if you get the array of urls you loose the id.
Its not enough to assume that the order of events returning is the
same as when you make the getSizes call. I am considering to use bulk
loader here for this. If I can prioritize the load order and force the
events in order then I can pop the id in an array and store them for
later retrieval like that.
Its not the end of the story as if you want any other kind of data the
same issues arrise for example if you want the description you get a
description back without knowing which id it belongs to.


On Apr 15, 1:09 am, "ja...@bangersandflash.net"

goodlux

unread,
May 23, 2009, 9:16:21 AM5/23/09
to ActionScript 3 Flickr Library
I took another look at this because it was really bugging me!

Here's the solution I came up with.

Basically what I was doing was creating one flickrService object, then
making all my calls though that. The problem here is that the
flickrService is detached from any parameters that you pass though it
(say a photo's id number).

So one way to fix this is to create a "param" variable on the
FlickrService object: So in FlickrService.as

public var param:String;

then in the constructor:

param = new String;


You could also extend the flickrService object with your own object,
say the paramFlickrService....or something like that.

Then create a seperate flickrService object for each time you make a
call to flickr.

for instance:

for each (var p:Photo in photos)
{

var fs:FlickrService = new FlickrService
(FLICKR_API_KEY)

fs.addEventListener
(FlickrResultEvent.PHOTOS_GET_SIZES, onGetPhotoInfo);
fs.photos.getSizes(p.id);
fs.params=p.id;


}

finally, when the response comes through

private function onGetPhotoInfo
(event:FlickrResultEvent):void {
var fs:FlickrService = event.target as FlickrService;

trace(fs.param);
trace(mx.utils.ObjectUtil.toString(event.data));

}


you can now get the initial information that you called the
FlickrService with.

I don't know if there is a better way to do this....if anyone has any
suggestions, please post...I have some more development that I want to
do with this, but I don't want to go too far in the wrong directly
then have start all over.

Thanks!
Reply all
Reply to author
Forward
0 new messages