【问题标题】:Not receiving Facebook picture via Graph API未通过 Graph API 接收 Facebook 图片
【发布时间】:2012-05-02 08:22:53
【问题描述】:

我似乎无法使用当前 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

【问题讨论】:

    标签: iphone ios xcode facebook-graph-api


    【解决方案1】:

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

    - (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"]]]];
    }
    

    【讨论】:

      【解决方案2】:

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

      iOS Facebook Graph API Profile picture link

      【讨论】:

        【解决方案3】:

        您还可以通过以下方式获取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];
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2012-05-24
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-04-19
          • 1970-01-01
          相关资源
          最近更新 更多