繁体   English   中英

Facebook个人资料图片未下载

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM