search result shows only one photo again and again why?

45 views
Skip to first unread message

Hafizur Rahman

unread,
Oct 22, 2009, 1:46:37 AM10/22/09
to objectiveflickr
I called a method to search photos in a specific test criteria and i
show it on my application. But it only show only one photo and repeat
this photo show again and again. I want to show more than 500 photos
10 per page. But can't. How is it possible please any one help me.

This is my source code that show only one photo repeat and repeat.


- (IBAction)nextRandomPhotoAction:(id)sender
{
NSLog(@"Button Pressed");
if (![flickrRequest isRunning]) {
[flickrRequest callAPIMethodWithGET:@"flickr.photos.search"
arguments:[NSDictionary dictionaryWithObjectsAndKeys:@"christmus",
@"text",@"100", @"per_page", nil]];
//arguments:[NSDictionary
dictionaryWithObjectsAndKeys:@"48834600@N00", @"group_id",
@"1",@"per_page", nil]];
}
}
//flickr.groups.pools.getPhotos
//flickr.photos.getRecent

- (void)flickrAPIRequest:(OFFlickrAPIRequest *)inRequest
didCompleteWithResponse:(NSDictionary *)inResponseDictionary
{
NSLog(@"Complete");
NSDictionary *photoDict = [[inResponseDictionary
valueForKeyPath:@"photos.photo"] objectAtIndex:0];

NSString *title = [photoDict objectForKey:@"title"];
if (![title length]) {
title = @"No title";
}

//NSURL *photoSourcePage = [flickrContext
photoWebPageURLFromDictionary:photoDict];
//NSDictionary *linkAttr = [NSDictionary
dictionaryWithObjectsAndKeys:photoSourcePage, NSAttributeName, nil];
//NSMutableString *attrString = [[[NSMutableString alloc]
initWithString:title attributes:linkAttr] autorelease];
//[[textView textStorage] setAttributedString:attrString];

NSURL *photoURL = [flickrContext
photoSourceURLFromDictionary:photoDict size:OFFlickrThumbnailSize];
NSString *htmlSource = [NSString stringWithFormat:
@"<html>"
@"<head>"
@" <style>body { margin: 0; padding: 0; } </style>"
@"</head>"
@"<body>"
@" <table border=\"0\" align=\"center\" valign=\"center\"
cellspacing=\"0\" cellpadding=\"0\" height=\"240\">"
@" <tr><td><img src=\"%@\" /></td></tr>"
@" </table>"
@"</body>"
@"</html>"
, photoURL];

[webView loadHTMLString:htmlSource baseURL:nil];
}

Thanks.

lukhnos

unread,
Oct 22, 2009, 2:01:02 AM10/22/09
to objectiveflickr
The way you make the API call flickr.photos.search asks Flickr to
always return the first 100 photos with the given keyword. Flickr
might cache the result, so it's not guaranteed (nor is it desirable in
practice) it's random. You need to implement the randomization
mechanism yourself. Also, per Flickr document, any search API call
also returns the total count and current page number of the response
"frame" you requested. Inspect the response dictionary (an NSLog will
do) for more information.

d.

Hafizur Rahman

unread,
Oct 22, 2009, 3:04:01 AM10/22/09
to objectiveflickr
Thanks for your reply. But your given sample shows the public photos
randomly. Pls specify me that, how can i show the total of 500-1000
photos and per page 10 photos. Can you give a example.

Thanks

lukhnos

unread,
Oct 22, 2009, 5:02:34 AM10/22/09
to objectiveflickr
The sample code RandomPublicPhoto calls the API
flickr.photos.getRecent against the global pool of Flickr photos, so
it's by nature randomized. If you search on a given keyword, on the
other hand, I don't see why the fetch result would be "random" enough
unless you're searching for a really trendy keyword, but Flickr
usually ensures the order of such search, so don't count on that.

You'll need to plan for making separate calls. For example, first
fetch 10 photos, get the total number of pages, then fetch the
remaining pages separately. Then use the fetched, aggregated pool to
show photos randomly.

d.

Hafizur Rahman

unread,
Oct 23, 2009, 4:00:29 AM10/23/09
to objecti...@googlegroups.com
Thanks again for your reply. Can you please specify me that how can i
access the first 10 photos and then the remaining. Please give me the
accessing source code if you can. Because i can't figure out this.

with regards
Hafiz
Reply all
Reply to author
Forward
0 new messages