我正在尝试在 Objective-c 中获取 facebook 个人资料图片的 URL。我这样做如下。
-(NSString *)getProfileURL:(NSString *)userId{
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
request = [[NSMutableURLRequest alloc] init];
NSString *requestURL = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture",userId];
NSLog(@"request url is %@",requestURL);
[request setURL:[NSURL URLWithString:requestURL]];
[request setHTTPMethod:@"GET"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setTimeoutInterval:60.0];
NSError *error;
NSURLResponse *response;
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *data=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
NSLog(@"data received from url: %@", data);
return data;
}
当我在浏览器中从 requestURL 复制并粘贴日志时,我得到了正确的图像。但是当我查看日志时"Data received from url: "
。我总是越来越 (null)
。
有什么帮助吗?