从xcode进行Glick休息调用flickr api

时间:2012-12-06 01:29:29

标签: xcode json api rest flickr

我正在尝试使用应用程序中的flickr.photos.getInfo方法进行GET调用。目标是使用它的ID获取有关照片的信息。

我的方法:

+(NSDictionary*)photoForId:(NSString *)photoID
{
    NSLog(@"photo id = %@", photoID);
    NSString *request=[NSString stringWithFormat:@"http://api.flickr.com/services/rest/flickr.photos.getInfo&photo_id=%@&format=json&nojsoncallback=1&extras=original_format,tags,description,geo,date_upload,owner_name&page=1&method=flickr.photos.search", photoID];

        NSLog(@"output=%@",[self executeFlickrFetch:request]);
    return [[[self executeFlickrFetch:request]valueForKey:@"photos.photo"]lastObject];

}

executeFlickrFetch方法:

+ (NSDictionary *)executeFlickrFetch:(NSString *)query
{
    query = [NSString stringWithFormat:@"%@&format=json&nojsoncallback=1&api_key=%@", query, FlickrAPIKey];
    query = [query stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  NSStringFromSelector(_cmd), query);
    NSData *jsonData = [[NSString stringWithContentsOfURL:[NSURL URLWithString:query] encoding:NSUTF8StringEncoding error:nil] dataUsingEncoding:NSUTF8StringEncoding];
    NSError *error = nil;
    NSDictionary *results = jsonData ? [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers|NSJSONReadingMutableLeaves error:&error] : nil;
    return results;
}

现在这个调用返回null。我知道执行获取是有效的,因为它是摄影师或地方拍摄的照片。只需要弄清楚照片的身份。

1 个答案:

答案 0 :(得分:0)

这是正确的要求:

NSString *request=[NSString stringWithFormat:@"http://api.flickr.com/services/rest/?method=flickr.photos.getInfo&photo_id=%@&format=json&nojsoncallback=1&extras=original_format,tags,description,geo,date_upload,owner_name&page=1", photoID];