[英]Facebook profile picture not downloading
我剛開始facebook集成,並在我的應用程序中下載用戶的詳細信息。 現在問題是我得到除了配置文件pic之外的所有其他細節,當NSloged返回null時。 我究竟做錯了什么。 我已經獲得了基本信息的權限。 請幫我。 Thanx提前。
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
// ...
}
}];
你永遠不能下載用戶形象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"]]
;
您通過請求此URL獲取登錄用戶的ID
https://graph.facebook.com/me
然后你可以通過創建這樣的URL來請求配置文件圖片:
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;
});
} );
} ];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.