iOS:如何获取 Facebook 相册照片的选择器 [英] iOS :How to get Facebook Album Photo's Picker

查看:24
本文介绍了iOS:如何获取 Facebook 相册照片的选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Facebook iOS SDK 是否像 UIImagePickerController 一样提供任何默认的 (Facebook) 相册照片选择器?

我听说过这个,所以搜索了很久,但没有找到任何东西.

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

解决方案

从 Facebook 导入

无需第三方工具即可从相册 Working For graph api 2.4、2.5、2.6、2.7、2.8 和 2.6、2.7、2.8 获取 Facebook 照片Facebook 图形 API 2.10

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

2) 然后在应用程序中选择平台以便更好地理解,请参阅以下屏幕截图

3) 选择 ios &按照向导中的所有步骤显示

4) 然后去graph api探索

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"] 处理程序:^(FBSDKLoginManagerLoginResult *result, NSError *error){[[[FBSDKGraphRequest分配]initWithGraphPath:@"我/专辑"参数:无HTTP方法:@GET"]startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {如果(!错误){//NSLog("%@",result);NSArray *data = [result valueForKey:@"data"];name = [数据 valueForKey:@"name"];ids = [数据 valueForKey:@"id"];[self.Fbtableview reloadData];}}];

9) 现在可以在 tableview cell for row 中按照代码类型获取专辑封面照片

目标 C

 coverid = [NSString stringWithFormat:@"/%@?fields=picture",[ids objectAtIndex:indexPath.row]];**//一张一张地传递专辑ID**/* 调用 API */FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]initWithGraphPath:coverid参数:无HTTP方法:@GET"];[请求 startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,识别结果,NSError *错误){//NSLog("%@",result);NSDictionary *pictureData = [result valueForKey:@"picture"];NSDictionary *redata = [pictureData valueForKey:@"data"];urlCover = [重数据 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)];}别的{img1= [[UIImageView alloc]initWithFrame:CGRectMake(10, 0, 40, 40)];}[img1 setImage:img];[img1 setContentMode:UIViewContentModeScaleAspectFit];[cell.contentView addSubview:img1];}];

10)现在获取相册照片 ID 的代码.

//**table didselect 方法中的代码**

目标 C

 NSString *strAlbumid = [NSString stringWithFormat:@"/%@/photos",[ids objectAtIndex:indexPath.row]];FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]initWithGraphPath:strAlbumid参数:无HTTP方法:@GET"];[请求 startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,识别结果,NSError *错误){//NSLog("%@",result);NSDictionary *data = [result valueForKey:@"data"];arrId = [数据 valueForKey:@"id"];照片视图控制器 * 照片视图控制器;if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){photoViewcontroller = [[PhotoViewControllerr alloc]initWithNibName:@"PhotoViewController_Ipad" bundle:nil];}别的{photoViewcontroller = [[PhotoViewControllerr alloc]initWithNibName:@"PhotoViewController" bundle:nil];}photoViewcontroller.picsArray = arrId;[photoViewcontroller.navigationController setNavigationBarHidden:YES];[[self navigationController] pushViewController: photoViewcontroller Animation:YES];}];

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

目标 C

NSString *strAlbumid = [NSString stringWithFormat:@"/%@/?fields=images",[self.picsArray objectAtIndex:indexPath.row]];FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]initWithGraphPath:strAlbumid参数:无HTTP方法:@GET"];[请求 startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,识别结果,NSError *错误){//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, ^{/* 从服务器获取图片... */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)];}别的{img1= [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];}img1.image = img;img1.contentMode = UIViewContentModeScaleAspectFit;[cell.contentView addSubview:img1];});});}];

12) 获取数据后,您必须在 facebook 中提交您的应用以提交您可以填写信息

1)应用详情

2)状态和评论

=====

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

享受.快乐的编码.

Is Facebook iOS SDK provide any default (Facebook) album Photo's picker like UIImagePickerController does?

I heard of this so searched for it from long but couldn't find anything.

Please let me know if someone have any thoughts on this. If its not, then I'll surely need to make my own.

解决方案

Import from Facebook

without third party tool get a facebook photos from album Working For graph api 2.4 , 2.5, 2.6,2.7,2.8 & Facebook graph api 2.10

1) Add App in Facebook developer account

2) then choose platform in app for better understand see following screen shot

3) Choose ios & follow All Step Display in wizard

4) then go to graph api explore https://developers.facebook.com/tools/explorer/145634995501895/

5)select your application in graph api explorer For more understand display screen shot

6) Click on Get token ..then click on get access token in a get token you can see so many permission for better understand see images

7) For Checking Your Permission on or off for getting album name & images display following screen shot

if user_photos permission is not on then display error see following screen shot

After completing step 7 either go for below steps or just download Coding files. I have put link Where you can download

Coding files for objective c

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

8) if there is no error display then following code in your viewDidLoad method in view controller.this code for getting album name & album ids.

objective 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];


             }


         }];

9) now getting album cover photos following code type in tableview cell for row

objective 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];


 }];

10)now code for getting album photos id.

 // code in **table didselect method**

objective 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];


}];

11) another view controller one now code for getting images in collection view cellforRow

objective 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];

         });
         });



}];

12) After getting data you must be submit your app in facebook for submit you can filling information in

1)app details

2)status and review

=====

If you have any query then I will help you

enjoy.happy coding.

这篇关于iOS:如何获取 Facebook 相册照片的选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆