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

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

问题描述

Facebook iOS SDK提供任何默认的(Facebook)相册照片的选择器,如 UIImagePickerController



我听说过这么久以来搜索过,但找不到任何东西。



请让我知道有人有任何想法。

解决方案

从Facebook导入



没有第三方工具从专辑获取Facebook照片工作对于图api 2.4,2.5,2.6,2.7,2.8& Facebook图表api 2.10



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



2)然后选择平台在应用程序中更好地了解看下面的屏幕截图





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



4)然后转到图表api探索



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





7)查看您的许可或取消相册名称&图片显示在屏幕截图之后





如果user_photos的权限不在,然后显示错误请参阅以下屏幕截图



完成步骤7后,或者只是下载Coding文件。我已经链接在哪里可以下载



为目标c编码文件



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



8)如果您的 viewDidLoad 方法中没有错误显示,则遵循以下代码在视图控制器。这个代码获取相册名称&专辑ids。



目标C

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

[loginManager logInWithReadPermissions:@ [@public_profile,@email,@user_friends,@user_photos]处理程序:^(FBSDKLoginManagerLoginResult * result,NSError * error)

{

[[FBSDKGraphRequest alloc]
initWithGraphPath:@me / albums
参数: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)现在获取专辑封面照片,代码类型在行列表 >



目标C

  coverid = [NSString stringWithFormat:@/%@?fields = picture,[ids objectAtIndex:indexPath.row]]; ** //通过相册ids逐个** 


/ *使API调用* /
FBSDKGraphRequest * request = [[FBSDKGraphRequest alloc]
initWithGraphPath :coverid
参数:nil
HTTPMethod:@GET];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection * connection,
id result,
NSError * error)
{

// NSLog(%@ ,结果);

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)现在用于获取相册照片的代码。

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

目标C

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



FBSDKGraphRequest * request = [[FBSDKGraphRequest alloc]
initWithGraphPath:strAlbumid
参数: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 = [[PhotoViewControlerr alloc] initWithNibName:@PhotoViewController_Ipadbundle:nil];
}
else
{
photoViewcontroller = [[PhotoViewControllerr alloc] initWithNibName:@PhotoViewControllerbundle:nil];
}


photoViewcontroller.picsArray = arrId;

[photoViewcontroller.navigationController setNavigationBarHidden:YES];




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


}];

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



目标C

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



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

// NSLog(%@ ,结果);
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)];
}
else
{

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



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

});
});



}];

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



1)应用详细信息



2)状态和评论



=====



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



enjoy.happy编码。


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天全站免登陆