2

我似乎无法使用当前的 iOS 图形方法正确检索用户的个人资料图片。

我的电话:self.pictureRequest = [facebook requestWithGraphPath:@"me/picture" andDelegate:self];

我对结果做了什么:

-(void)request:(FBRequest *)request didLoad:(id)result{
    if(request == self.pictureRequest){
        UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
        image.image = [UIImage imageWithData:result];
        [self.view addSubview:image];
        NSLog("result is %@", result);
    }

所以我现在只是想获取个人资料图片。结果在控制台中显示为 null。我想这意味着我实际上没有得到结果?(我试过if(result) NSLog(@"got a result")但它没有返回,所以我猜结果不是由 fb 发回的?)

有任何想法吗?我也在这里查找了一个类似的问题,但不确定他们有什么不同: Problem getting Facebook pictures via iOS

4

3 回答 3

2

好吧,我可以像这样检索用户图片和其他信息..试试看

- (void)fetchUserDetails {
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   @"SELECT uid, name, pic, email FROM user WHERE uid=me()", @"query",nil];

    [fb requestWithMethodName:@"fql.query"
                                     andParams:params
                                 andHttpMethod:@"POST"
                                   andDelegate:self];


}//Call this function after the facebook didlogin

并在请求 didLoad

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

    if([request.url rangeOfString:@"fql.query"].location !=NSNotFound)
    {
        if ([result isKindOfClass:[NSArray class]] && [result count]>0) {
            result = [result objectAtIndex:0];
        }
        if ([result objectForKey:@"name"]) {

            self.fbUserName = [result objectForKey:@"name"];

           // Get the profile image
            UIImage *fbimage = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[result objectForKey:@"pic"]]]];
}
于 2012-05-02T09:27:36.613 回答
0

您还可以通过以下方式获取 fb 个人资料图片网址,

NSString *userFbId;
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture", userFbId]];

NSData *imageData = [[NSData alloc] initWithContentsOfURL:url];
self.userProfileImage.image = [UIImage imageWithData:imageData];
于 2014-01-13T12:12:50.560 回答
0

如果您想使用 requestWithGraph 路径(而不是像@Malek_Jundi 提供的 requestWithMethodName )获取图片 URL,请在此处查看我的答案:

iOS Facebook Graph API 个人资料图片链接

于 2012-05-08T06:33:00.463 回答