[英]Facebook profile picture not downloading
I just started facebook integration, and in my app am downloading details of the user. 我刚开始facebook集成,并在我的应用程序中下载用户的详细信息。 Now the thing is I am getting all other details except the profile pic which when NSloged returns null. 现在问题是我得到除了配置文件pic之外的所有其他细节,当NSloged返回null时。 What am I doing wrong. 我究竟做错了什么。 I have given permissions for basic info. 我已经获得了基本信息的权限。 Please help me. 请帮我。 Thanx in advance. Thanx提前。
FBRequest *request = [FBRequest requestForMe]; FBRequest * request = [FBRequest requestForMe];
// Send request to Facebook
[request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
// result is a dictionary with the user's Facebook data
NSDictionary *userData = (NSDictionary *)result;
nickname.text= userData[@"name"];
firstName.text=userData [@"first_name"];
lastName.text=userData[@"last_name"];
city.text=userData[@"user_location"];
gender.text= userData[@"gender"];
dateOfBirth.text = userData[@"birthday"];
NSURL *pictureURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large", userData[@"id"]]];
NSData *data =[NSData dataWithContentsOfURL:pictureURL];
NSLog(@" profile pic data = %@", data);
self.imageToUpload.image=[UIImage imageWithData:data];
NSString *imgstr=[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"%@",imgstr);
[PFUser logOut];
// Now add the data to the UI elements
// ...
}
}];
you can never download user image facebook dont allow it i send weeks on it a while ago but didn't work in any way. 你永远不能下载用户形象facebook不允许它我前几周发送它但是没有以任何方式工作。
but from my experience you don't need image @ all just url will work every place you need if you need help on how to display image i can help you 但根据我的经验,你不需要图像@所有只是url将在你需要的每个地方工作如果你需要帮助如何显示图像我可以帮助你
http://m-farhan.com/2014/03/ios-facebook-sdk-tutorial/ http://m-farhan.com/2014/03/ios-facebook-sdk-tutorial/
check step (6) 检查步骤(6)
and download project there is library SDWebImage folder drag in your project 并下载项目,在您的项目中拖动库SDWebImage文件夹
#import "SDWebImage/UIImageView+WebCache.h"
[userImage setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large",[user objectForKey:@"id"]]]
placeholderImage:[UIImage imageNamed:@"unknownUser.png"]]
;
You get the id of logged in user by requesting this url 您通过请求此URL获取登录用户的ID
https://graph.facebook.com/me
and then you can request for the profile pic by creating url like this: 然后你可以通过创建这样的URL来请求配置文件图片:
https://graph.facebook.com/<userid>/picture
I hope this helps. 我希望这有帮助。
You may get exact idea here 你可以在这里得到确切的想法
-(void)getFacebookAccounts {
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
NSDictionary *options = [[NSDictionary alloc] initWithObjectsAndKeys:
@"appid", ACFacebookAppIdKey,
[NSArray arrayWithObject:@"email"], ACFacebookPermissionsKey,
nil];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
[accountStore requestAccessToAccountsWithType:accountType options:options
completion:^(BOOL granted, NSError *error) {
if (granted && !error) {
accountsList = (NSMutableArray*)[accountStore accountsWithAccountType:accountType];
int NoOfAccounts = [accountsList count];
if (NoOfAccounts > 1) {
NSLog(@"device has more then one twitter accounts %i",NoOfAccounts);
}
else
{
NSLog(@"device has single twitter account : 0");
if([accountsList count] > 0)
{
myAccount = [accountsList objectAtIndex:0];
[self getProfilePic];
}
else
{
UIAlertView *altviw=[[UIAlertView alloc] initWithTitle:@"Error" message:@"Set an account in the settings of the device" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[altviw show];
altviw=nil;
}
}
}
else
{
// show alert with information that the user has not granted your app access, etc.
}
} ];
}
-(void) getProfilePic{
NSURL *url = [NSURL URLWithString:@"https://graph.facebook.com/me"];
NSDictionary *p = [NSDictionary dictionaryWithObjectsAndKeys:myAccount.username, @"screen_name", nil];
SLRequest *FBrequest= [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodGET
URL:url
parameters:p];
[FBrequest setAccount:myAccount];
[FBrequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResposnse, NSError *error)
{
if (error) {
}
NSError *jsonError = nil;
// Convert the response into a dictionary
NSDictionary *dictResponse = [NSJSONSerialization JSONObjectWithData:responseData options:(NSJSONReadingOptions)NSJSONWritingPrettyPrinted error:&jsonError];
NSString *strId1= [dictResponse objectForKey:@"id"];
NSString *strurl=[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture", strId1];
if(!arrmPics)
{
arrmPics=[[NSMutableArray alloc] init];
}
dispatch_async
(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSData *imageData =
[NSData dataWithContentsOfURL:
[NSURL URLWithString: strurl]];
UIImage *image = [UIImage imageWithData:imageData];
dispatch_async(dispatch_get_main_queue(), ^{
[arrmPics addObject:imageData];
imgviw.image=image;
});
} );
} ];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.