3

我们正在尝试获取用户的个人资料图片 URL。我们正在经历随机行为。有时权限对话框会按预期在浏览器中打开,但有时浏览器会打开用户主页。任何想法为什么?

NSArray *permissions = [[NSArray alloc] initWithObjects:@"email",@"publish_actions", nil];
FBSession* session;

session = [[FBSession alloc] initWithAppID:@"xxx" permissions:permissions defaultAudience:FBSessionDefaultAudienceEveryone urlSchemeSuffix:nil tokenCacheStrategy:nil];

[FBSession setActiveSession:session];


// get image

NSString *path = [[NSString alloc] initWithFormat:@"%@/picture?redirect=false&width=170&height=170",fuid];
[FBRequestConnection startWithGraphPath:path completionHandler:^]
4

1 回答 1

1

这就是我收集用户个人资料图片的方式,尽管有很多方法可以做到这一点:

一旦用户登录,我将使用通知(或任何其他方法)进行通知,然后调用方法来收集 Facebook 个人资料图片。一旦他们登录,您就可以将他们的 facebook Id 传递给一个值。(kUserFacebookIDKey)

NSLog(@"Downloading user's profile picture");
// Download user's profile picture
NSURL *profilePictureURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large", self.kUserFacebookIDKey];
NSURLRequest *profilePictureURLRequest = [NSURLRequest requestWithURL:profilePictureURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0f]; // Facebook profile picture cache policy: Expires in 2 weeks
[NSURLConnection connectionWithRequest:profilePictureURLRequest delegate:self];

注意:您需要将标题更新为 < NSURLConnectionDataDelegate> 并为NSMutableData *_data;

然后处理响应:

#pragma mark - NSURLConnectionDataDelegate
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    _data = [[NSMutableData alloc] init];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    [_data appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    [TESTUtility processFacebookProfilePictureData:_data];
}

然后你可以对文件做你想做的事。通常我缓存文件,然后检查缓存的文件是否与新文件匹配,依此类推......

于 2013-07-30T10:03:27.153 回答