我们正在尝试获取用户的个人资料图片网址。我们正在经历随机行为。有时,按预期在浏览器中打开权限对话框,但有时浏览器会打开用户主页。任何想法为什么?
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:^]
答案 0 :(得分: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];
}
然后你可以用文件做你想做的事。通常我会缓存文件,然后检查缓存的文件是否与新的匹配等等......