简体   繁体   中英

Return Facebook profile picture

Is that possible to retrieve the name of the picture file from the Facebook profile picture?

What I want to do is this: When the user logs in I will retrieve the user's profile pic and then save it on a file. However, I want to always check whether the user updated the picture on Facebook and if yes save it on the file again.

Is it possible to get the name of the file, and therefore I can compare them?

Here is the code that I use to download the picture:

NSString *urlString = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?width=100&height=100",[[PFUser currentUser] objectForKey:@"fbId"]];                
    NSURL *url = [NSURL URLWithString:urlString];
    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];

    AFHTTPRequestOperation *requestOperation = [[AFHTTPRequestOperation alloc] initWithRequest:urlRequest];
    requestOperation.responseSerializer = [AFImageResponseSerializer serializer];

    [requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject){
        profilePicture = [UIImage imageWithData: operation.responseData];
        NSDictionary<FBGraphUser> *me = (NSDictionary<FBGraphUser> *)responseObject;
        NSLog(@"ResponseObject %@", me.username);
        NSLog(@"Profile Image %@",profilePicture);
        [self saveImageOnDisk:profilePicture];
}];

You should not need to do either. Request it again. The URL loading subsystem will check it's cached version and send Facebook an If-Modified-Since (conditional GET) request to check for a newer version. You do not have to do anything special, the system does this for you. If there is newer data available it will get it, otherwise it will use the data it already cached.

URL Loading System: Understanding Cache Access

RFC2616: HTTP Caching

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM