将Facebook API与Objective C结合使用以查找随机的Facebook用户图像 [英] Use Facebook API with Objective C to find random Facebook user image

查看:74
本文介绍了将Facebook API与Objective C结合使用以查找随机的Facebook用户图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个返回随机Facebook个人资料图片的应用.到目前为止,我在下面的代码中生成了一个随机的配置文件ID,该ID有时会返回真实的配置文件,但有时却不会,仅显示通用的蓝色Facebook面孔.当我在实际的网站图形API上使用给定的数字时,它只会返回false.我的问题是我应该如何放置代码,以便如果生成的随机数返回错误的配置文件,它只会不断生成新的随机数,直到返回真实的配置文件,从而生成真实的图片为止?预先感谢

I am building an app that returns a random Facebook profile picture. So far I have the code below generating a random profile ID which sometimes does return a real profile but sometimes doesnt and just shows the generic blue Facebook face. When I use the given number on the actual website graph API it just returns false. My question is how would I put the code in so that if the random number generated returns a false profile, it just keeps generating a new random number until a real profile is returned, thus a real picture? Thanks in advance

@implementation FacebookPicturesViewController

- (IBAction) nextImagePush {

    NSString *prefix = @"http://graph.facebook.com/";
    NSString *profileId = [NSString stringWithFormat:@"%09d", abs(arc4random())];
    NSLog(@"profileId: %@", profileId);
    NSString *suffix = @"/picture?type=large";
    NSString* url= [NSString stringWithFormat:@"%@%@%@", prefix, profileId, suffix];
    UIImage *img = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:url]]];
    [imageView setImage:img];
    imageCount++;

    NSLog(@"profileId: %@", profileId);

    if (imageCount >= [imageArray count]){
        imageCount = 0;
    }
}

推荐答案

听起来像您的问题是,由于Facebook总是返回默认图像,您无法确定它是否是真实图像?

It sounds like your problem is that you can't tell if it's a real image or not because Facebook always returns a default image?

first 不仅直接请求picture?type=large(总是返回图像),还向 http://graph.facebook.com/USERID 并读取该响应-将为false,如果不是真实用户则为

Instead of just requesting the picture?type=large directly (which always returns an image), first make a request to the http://graph.facebook.com/USERID and read that response - which will be false or something if it's not a real user.

浏览直到找到真正的用户,然后然后请求图像URL.

Loop through until you find a real user, then request the image URL.

我不确定您为什么要这么做...但是祝您好运.

I'm not sure why you would want to do this though... but good luck.

这篇关于将Facebook API与Objective C结合使用以查找随机的Facebook用户图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆