使用 UIImageView 显示随机的 Facebook 个人资料图片
我有一个非常简单的 UIImageView
,我可以用它来显示来自 facebook 的个人资料图片(代码如下所示)。要获取图片的 URL,我只需转到任何人的个人资料(无论您是否登录、将他们作为朋友等都没关系),右键单击他们的个人资料图片并选择“复制图像地址”并将其粘贴到代码中。我知道您还可以通过更改此 http://graph.facebook.com/harryhall1/picture?type=large
的图片网址来获取图片,两者都可以正常工作。
现在,我的问题是我可以让它从随机个人资料生成个人资料图片吗?在我看来,这应该是可能的,因为我不必登录 Facebook 等来查看任何随机人员的个人资料图片,我可以右键单击他们的个人资料图片并保存它,复制网址等,等等。我只是不知道如何获取随机配置文件 ID。我真的很感激对这些人的任何帮助。
@interface NextImageViewController : UIViewController {
IBOutlet UIImageView *imageView;
NSInteger imageCount;
NSArray *imageArray;
}
- (IBAction) nextImagePush;
@end
@implementation NextImageViewController
- (IBAction) nextImagePush {
UIImage *img = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://profile.ak.fbcdn.net/hprofile-ak-snc4/211479_517418990_3896134_n.jpg"]]];
[imageView setImage:img];
imageCount++;
}
I have a very simple UIImageView
that I can get to show a profile picture from facebook (code shown below). To get the URL of the picture I just go to anyones profile (doesnt matter if youre logged in, got them as a friend etc), right click on their profile picture and select 'copy image address' and pasted it into the code. I know you can also get the picture by changing the picture url for this http://graph.facebook.com/harryhall1/picture?type=large
, either works fine.
Now, my question is can I get this to generate a profile picture from a random profile? In my mind this should be possible because I do not have to be logged in to facebook etc to view any random persons profile picture, I can right click on their profile picture and save it, copy the url etc, etc. I'm just not sure how to get a random profile id. I really would appreciate any help on this guys.
@interface NextImageViewController : UIViewController {
IBOutlet UIImageView *imageView;
NSInteger imageCount;
NSArray *imageArray;
}
- (IBAction) nextImagePush;
@end
@implementation NextImageViewController
- (IBAction) nextImagePush {
UIImage *img = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://profile.ak.fbcdn.net/hprofile-ak-snc4/211479_517418990_3896134_n.jpg"]]];
[imageView setImage:img];
imageCount++;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用 Facebook 的 Graph API 中的信息。您无需获得授权或任何其他信息即可获取基本的个人资料信息。数据以 JSON 格式返回,如下所示 - http://graph.facebook.com/?id=dunenkoff 。您可以在
id
查询参数中提供数字用户 ID。有关 Graph API 的更多信息,请参见此处 - http://developers.facebook.com/docs/reference/api /
Try using info from Facebook's Graph API. You don't have to be authorized or anything to get basic profile info. Data is returned in JSON format, like this - http://graph.facebook.com/?id=dunenkoff. You can supply numerical user id's into
id
query argument.More info on Graph API here - http://developers.facebook.com/docs/reference/api/