ios,Facebook和获取个人资料图片 [英] ios, facebook and getting profile image

查看:157
本文介绍了ios,Facebook和获取个人资料图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取Facebook朋友的个人资料图片。我知道我可以通过获取用户的ID和使用此链接来执行此操作:userID / picture> http://graph.facebook.com/ userID / picture。有更容易的方法来获取个人资料图片直接来自facebook sdk?

解决方案

如何获取个人资料图片的网址?然后使用类似 SDWebImage 显示图像并将其缓存到设备或任何可以通过传递URL来显示和缓存图像的开源库然后,获取他的朋友的userID,保存在NSArray中,然后创建一个fql。



pre> - (void)getFriendsInfo:(NSArray *)userIDs
{
//准备参数
NSMutableString * paramStr = [[NSMutableString alloc] init] ;
for(int i = 0; i< [userIDs count]; i ++){
if([[userIDs objectAtIndex:i] isKindOfClass:[NSDecimalNumber class]]){
NSString * tempParam = [NSString stri ngWithString:[[userIDs objectAtIndex:i] stringValue]];
[paramStr appendFormat:@'%@',,tempParam];
}
}
[paramStr appendFormat:@%@,@'9999999999999'];
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSString stringWithFormat:@SELECT uid,name,pic FROM user WHERE uid IN(%@),tempParam],@query,
nil];

//在我的情况下,我宣布Facebook * facebook;在我的应用程序委托中使用最新的fb sdk
MyAppDelegate * delegate =(MyAppDelegate *)[[UIApplication sharedApplication] delegate];
[[delegate facebook] requestWithMethodName:@fql.query
andParams:params
andHttpMethod:@POST
andDelegate:self];
}

处理委托方法中的数据

   - (void)request:(FBRequest *)request didLoad:(id)result 


I want to get profile image of facebook friends. I know I can do this in code by getting id of user and using this link: userID/picture">http://graph.facebook.com/userID/picture. Is there easier way to get profile image directly from facebook sdk?

解决方案

what about getting the url of the profile picture? then use something like SDWebImage to display the image and cache it to device. or any open source library that can display and cache image just by passing the url to it?

then, get the userIDs of his friends. save them in NSArray. then create a fql.

-(void)getFriendsInfo:(NSArray*)userIDs
{
    //prepare param
    NSMutableString *paramStr = [[NSMutableString alloc]init];
       for (int i = 0; i<[userIDs count]; i++) {
        if ([[userIDs objectAtIndex:i] isKindOfClass:[NSDecimalNumber class]]) {
        NSString *tempParam = [NSString stringWithString:[[userIDs objectAtIndex:i]stringValue]];
        [paramStr appendFormat:@"'%@',", tempParam];
    }
}
    [paramStr appendFormat:@"%@",@"'9999999999999'"];
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               [NSString stringWithFormat:@"SELECT uid, name, pic FROM user WHERE uid IN (%@)", tempParam], @"query",
                               nil];

    //in my case, I declared  Facebook *facebook; in my app delegate using the latest fb sdk
    MyAppDelegate *delegate = (MyAppDelegate *) [[UIApplication sharedApplication] delegate];
    [[delegate facebook] requestWithMethodName:@"fql.query"
                                 andParams:params
                             andHttpMethod:@"POST"
                               andDelegate:self];
}

handle the data in delegate method

- (void)request:(FBRequest *)request didLoad:(id)result

这篇关于ios,Facebook和获取个人资料图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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