Domanda

I'm fetching user profile images from Facebook like this:

[FBRequestConnection startWithGraphPath:@"me/albums" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {

        if (error)
            FRLogError(@"ERROR %@", error);
        else
        {
            NSDictionary *dataDictionary = [result objectForKey:@"data"];

            NSString *albumId = nil;

            for (NSDictionary *dictionary in dataDictionary)
            {
                if ([[dictionary objectForKey:@"name"] isEqualToString:@"Profile Pictures"])
                {
                    albumId = [dictionary objectForKey:@"id"];
                    break;
                }
            }

            [FBRequestConnection startWithGraphPath:[NSString stringWithFormat:@"%@/photos", albumId] completionHandler:^(FBRequestConnection *_connection, id _result, NSError *_error){

                NSArray             *photos     = [_result objectForKey:@"data"];
                NSMutableDictionary *photoLinks = [NSMutableDictionary dictionary];

                for (NSDictionary *dict in photos)
                {
                    NSString *photoId = dict[@"id"];
                    NSString *link    = dict[@"source"];
                    [photoLinks setObject:link forKey:photoId];
                }

                [[FRDataStorageManager sharedManager] saveImagesFromLinks:photoLinks];
        }];

        }
    }];

And it gives me say three links to images which i obtain later. Is there any possibility to find out which one of them is actually the one which is chosen by user to be the main profile picture?

È stato utile?

Soluzione

There's no such field mentioned in the documentation that could tell you if its a profile picture or not.

But one thing you can do-

Make the call- /me/picture?redirect=0. This will return you a url. (example)

Now, in your code you can simply check if this url contains photoId (a substring), if yes- its a profile picture.

Or, you can fetch the photo id of the profile pic before hand from /me/picture?redirect=0 and then check if the photoId equals this- its a profile picture. (depends how you want to implement)

(This is a full-proof method yet I'm not sure its the best way to do so)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top