我刚刚启动了facebook集成,并在我的应用程序中下载了用户的详细信息。 现在问题是我得到除了配置文件pic之外的所有其他细节,当NSloged返回null时。 我究竟做错了什么。我已经获得了基本信息的权限。 请帮我。提前完成。
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
// ...
}
}];
答案 0 :(得分:1)
你永远不能下载用户形象facebook不允许它我不久前发送了几周但是没有以任何方式工作。
但根据我的经验,您不需要图像@所有只需url就能在您需要帮助的地方工作,如果您需要有关如何显示图像的帮助我可以帮助您
http://m-farhan.com/2014/03/ios-facebook-sdk-tutorial/
检查步骤(6)
并下载项目,在项目中拖动库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"]]
;
答案 1 :(得分:1)
通过请求此网址
获取登录用户的IDhttps://graph.facebook.com/me
然后您可以通过创建这样的网址来请求个人资料照片:
https://graph.facebook.com/<userid>/picture
我希望这会有所帮助。
你可以在这里得到确切的想法
-(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;
});
} );
} ];
}