gpt4 book ai didi

iphone - iOS 应用程序下载 flickr 照片

转载 作者:行者123 更新时间:2023-11-28 22:51:19 24 4
gpt4 key购买 nike

我正在为一所学校开发一个应用程序。他们将照片保存在 flickr 上。他们希望在他们的应用程序中有一个照片库页面,可以从他们的 flickr 页面中提取照片。我想知道从 flickr 下载照片的最简单方法是什么:1.我不想上传任何照片。2. 我不希望用户必须登录。3. 我无法提供单张照片的网址,因为学校更新他们的 flickr 的频率可能比我更新应用程序的频率更高。我只想让该应用提取他们相册中的所有照片。

非常感谢,卢克

最佳答案

试试这段代码

-(void)getUserID{

NSString *methodName = @"flickr.people.findByUsername";

NSString *userName = @"<Your_Username>";

NSString *urlString = [NSString stringWithFormat:@"%@?method=%@&api_key=%@",kFlickrAPIURL,methodName,kFlickrAPIKey];
urlString = [NSString stringWithFormat:@"%@&username=%@&format=%@&nojsoncallback=1", urlString,userName,kFlickrResponseFormat];

NSURL *url = [NSURL URLWithString:urlString];

userIDRequest = [[NSURLRequest alloc] initWithURL: url];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:userIDRequest delegate:self];
[connection release];
}

-(void)getUserPhotos:(NSString *)userID{

NSString *methodName = @"flickr.people.getPhotos";

NSString *urlString = [NSString stringWithFormat:@"%@?method=%@&key=%@",kFlickrAPIURL,methodName,kFlickrAPIKey];

urlString = [NSString stringWithFormat:@"%@&user_id=%@&format=%@&nojsoncallback=1",urlString,userID,kFlickrResponseFormat];

NSURL *url = [NSURL URLWithString:urlString];

imagesRequest = [[NSURLRequest alloc] initWithURL: url];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:imagesRequest delegate:self];
[connection release];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
NSError *error = nil;

NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];
if (userIDRequest == connection.originalRequest)
{
NSString *userId = [[jsonDic objectForKey:@"user"] objectForKey:@"id"];
if (userId != nil)
[self getUserPhotos:userId];
} else if (imagesRequest == connection.originalRequest) {

NSArray *photos = [[jsonDic objectForKey:@"photos"] objectForKey:@"photo"];

for (NSDictionary *photo in photos)
{
// Get title of the image
NSString *title = [photo objectForKey:@"title"];

// Build the URL to where the image is stored (see the Flickr API)
// In the format http://farmX.static.flickr.com/server/id/secret
// Notice the "_s" which requests a "small" image 75 x 75 pixels
NSString *photoURLString = [NSString stringWithFormat:@"http://farm%@.static.flickr.com", [photo objectForKey:@"farm"]];
photoURLString = [NSString stringWithFormat:@"%@/%@/%@_%@_s.jpg", photoURLString, [photo objectForKey:@"server"], [photo objectForKey:@"id"], [photo objectForKey:@"secret"]];

}
}

}

关于iphone - iOS 应用程序下载 flickr 照片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11923554/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com