iOS:如何获得Facebook专辑照片的选择器

Hem*_*ang 13 objective-c facebook-graph-api ios facebook-ios-sdk swift

Facebook iOS SDK是否提供任何默认(Facebook)专辑Photo's picker UIImagePickerController

我听说过这么长时间搜索它但找不到任何东西.

如果有人对此有任何想法,请告诉我.如果不是,那么我肯定需要自己做.

Mau*_*hah 24

从Facebook导入

没有第三方工具从相册获取Facebook照片工作图图api 2.4,2.5,2.6,2.7,2.8和Facebook图api 2.10

1)在Facebook开发者帐户中添加应用程序

2)然后在app中选择平台以便更好地了解以下屏幕截图

在此输入图像描述

3)选择ios并按照向导中的All Step Display显示

4)然后去图形api探索https://developers.facebook.com/tools/explorer/145634995501895/

5)在图形api explorer中选择你的应用程序更多了解显示屏幕截图

在此输入图像描述

6)单击获取令牌..然后单击获取令牌中的获取访问令牌,您可以看到许多权限,以便更好地了解查看图像

在此输入图像描述

7)打开或关闭您的权限,以便在屏幕截图后显示相册名称和图像

在此输入图像描述

如果未启用user_photos权限,则显示错误,请参见以下屏幕截图 在此输入图像描述

完成步骤7后,请执行以下步骤或只下载编码文件.我已经把链接放在哪里可以下载

编码目标c的文件

https://www.dropbox.com/s/1ysek035ek88xuw/FacebookAlbum%20Demo.zip?dl=0

8)如果没有错误显示,则在视图控制器的viewDidLoad方法中跟随代码.这个代码用于获取专辑名称和专辑ID.

目标C.

     FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];

    [loginManager logInWithReadPermissions:@[@"public_profile", @"email", @"user_friends",@"user_photos"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)

    {

        [[[FBSDKGraphRequest alloc]
          initWithGraphPath:@"me/albums"
          parameters: nil
          HTTPMethod:@"GET"]
         startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
             if (!error) {

               //  NSLog("%@",result);

                 NSArray *data = [result valueForKey:@"data"];


                 name = [data valueForKey:@"name"];

                 ids = [data valueForKey:@"id"];


                 [self.Fbtableview reloadData];


             }


         }];
Run Code Online (Sandbox Code Playgroud)

9)现在在tableview单元格中获取代码类型的专辑封面照片

目标C.

 coverid = [NSString stringWithFormat:@"/%@?fields=picture",[ids objectAtIndex:indexPath.row]]; **// pass album ids one by one**


/* make the API call */
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                              initWithGraphPath:coverid
                              parameters:nil
                              HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                      id result,
                                      NSError *error)
 {

    // NSLog("%@",result);

     NSDictionary *pictureData  = [result valueForKey:@"picture"];

     NSDictionary *redata = [pictureData valueForKey:@"data"];

     urlCover = [redata valueForKey:@"url"];



     NSURL *strUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@",urlCover]];

     NSData *data = [NSData dataWithContentsOfURL:strUrl];
     UIImage *img = [[UIImage alloc] initWithData:data];
     UIImageView *img1;

     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
     {
         img1= [[UIImageView alloc]initWithFrame:CGRectMake(10, 0, 50, 50)];
     }
     else
     {
         img1= [[UIImageView alloc]initWithFrame:CGRectMake(10, 0, 40, 40)];
     }



     [img1 setImage:img];
     [img1 setContentMode:UIViewContentModeScaleAspectFit];
     [cell.contentView addSubview:img1];


 }];
Run Code Online (Sandbox Code Playgroud)

10)现在获取专辑照片ID的代码.

 // code in **table didselect method**
Run Code Online (Sandbox Code Playgroud)

目标C.

   NSString *strAlbumid = [NSString stringWithFormat:@"/%@/photos",[ids objectAtIndex:indexPath.row]];



FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                              initWithGraphPath:strAlbumid
                              parameters:nil
                              HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                      id result,
                                      NSError *error) {

    // NSLog("%@",result);
    NSDictionary *data = [result valueForKey:@"data"];

    arrId = [data valueForKey:@"id"];



    PhotoViewControllerr *photoViewcontroller;

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        photoViewcontroller = [[PhotoViewControllerr alloc]initWithNibName:@"PhotoViewController_Ipad" bundle:nil];
    }
    else
    {
        photoViewcontroller = [[PhotoViewControllerr alloc]initWithNibName:@"PhotoViewController" bundle:nil];
    }


    photoViewcontroller.picsArray = arrId;

    [photoViewcontroller.navigationController setNavigationBarHidden:YES];




    [[self navigationController] pushViewController:  photoViewcontroller animated:YES];


}];
Run Code Online (Sandbox Code Playgroud)

11)另一个视图控制器现在用于在集合视图cellforRow中获取图像的代码

目标C.

NSString *strAlbumid = [NSString stringWithFormat:@"/%@/?fields=images",[self.picsArray objectAtIndex:indexPath.row]];



FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                              initWithGraphPath:strAlbumid
                              parameters:nil
                              HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                      id result,
                                      NSError *error)
{

    //NSLog("%@",result);
    picture_images = [result valueForKey:@"images"];

    NSMutableArray *picCount = [picture_images objectAtIndex:picture_images.count - 1];



     NSURL *strUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@",[picCount valueForKey:@"source"]]];


    dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
    dispatch_async(q, ^{
        /* Fetch the image from the server... */
       NSData *data = [NSData dataWithContentsOfURL:strUrl];
         UIImage *img = [[UIImage alloc] initWithData:data];
         dispatch_async(dispatch_get_main_queue(), ^{

         if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
         {

         img1= [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 200, 200)];
         }
         else
         {

         img1= [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
         }



         img1.image = img;
         img1.contentMode = UIViewContentModeScaleAspectFit;
         [cell.contentView addSubview:img1];

         });
         });



}];
Run Code Online (Sandbox Code Playgroud)

12)获取数据后,您必须在Facebook上提交您的应用程序以提交您可以填写信息

1)应用程序详细信息

2)状态和审查

=====

如果您有任何疑问,我会帮助您

enjoy.happy编码.