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

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

问题描述

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

我听说过这个,所以找了很长时间,但找不到任何东西.

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

解决方案

从 Facebook 导入

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

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

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

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

4) 然后去图 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"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error){[[[FBSDKGraphRequest 分配]initWithGraphPath:@"我/专辑"参数:无HTTPMethod:@"GET"]startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id 结果, NSError *error) {如果(!错误){//NSLog("%@",result);NSArray *data = [result valueForKey:@"data"];name = [data valueForKey:@"name"];ids = [data valueForKey:@"id"];[self.Fbtableview reloadData];}}];

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

目标 C

 coverid = [NSString stringWithFormat:@"/%@?fields=picture",[ids objectAtIndex:indexPath.row]];**//一一传递专辑ID**/* 进行 API 调用 */FBSDKGraphRequest *request = [[FBSDKGraphRequest 分配]initWithGraphPath:coverid参数:无HTTPMethod:@"GET"];[请求 startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,身份证结果,NSError *错误){//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)];}别的{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 分配]initWithGraphPath:strAlbumid参数:无HTTPMethod:@"GET"];[请求 startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,身份证结果,NSError *错误){//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];}别的{photoViewController = [[PhotoViewControllerr alloc]initWithNibName:@"PhotoViewController" bundle:nil];}photoViewcontroller.picsArray = arrId;[photoViewcontroller.navigationController setNavigationBarHidden:YES];[[self navigationController] pushViewController: photoViewcontroller 动画:YES];}];

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

目标 C

NSString *strAlbumid = [NSString stringWithFormat:@"/%@/?fields=images",[self.picsArray objectAtIndex:indexPath.row]];FBSDKGraphRequest *request = [[FBSDKGraphRequest 分配]initWithGraphPath:strAlbumid参数:无HTTPMethod:@"GET"];[请求 startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,身份证结果,NSError *错误){//NSLog("%@",result);图片图片 = [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天全站免登陆