0
我正嘗試使用應用中的flickr.photos.getInfo方法進行GET調用。目標是使用它的id來獲取關於照片的信息。從xcode發出一個GET休息呼叫flickr api
我的方法:
+(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。我知道執行獲取作品,因爲它是由攝影師或地點獲取照片。只需要找出照片ID。