iOS:如何获取Facebook相册照片的选取器

Facebook的iOS SDK提供任何默认(Facebook)相册像UIImagePickerController照片的select器呢?

我听说这个东西很长时间找不到,但找不到任何东西。

请让我知道,如果有人对此有任何想法。 如果不是的话,那我一定要自己做。

从Facebook导入

没有第三方工具从相册中获取Facebook照片Working for graph api 2.4,2.5,2.6,2.7,2.8和Facebookgraphicsapi 2.10

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

2)然后在应用程序中select平台,以便更好地了解下面的屏幕截图

在这里输入图像描述

3)selectios并按照向导中的所有步骤显示

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

5)在graphicsapi资源pipe理器中select你的应用程序为更多的理解显示屏幕截图

在这里输入图像描述

6)点击获取令牌..然后点击获取令牌获取令牌,你可以看到这么多的权限,以更好地理解看到的图像

在这里输入图像描述

7)检查您的权限开启或closures,以获得专辑名称和图像显示下面的屏幕截图

在这里输入图像描述

如果user_photos权限不在,则显示错误请参阅下面的屏幕截图 在这里输入图像描述

完成第7步之后,请执行以下步骤或仅下载编码文件。 我已经把链接哪里可以下载

为目标编码文件c

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

8)如果没有错误显示,那么下面的代码在你viewDidLoad方法在视图controller.this代码获取专辑名称和专辑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]; } }]; 

9)现在获取专辑封面照片,在tableview单元格中的代码types为row

目标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)现在代码获取专辑照片ID。

  // code in **table didselect method** 

目标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)另一个视图控制器现在代码获取图像收集视图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]; }); }); }]; 

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

1)应用程序的细节

2)状态和审查

=====

如果你有任何疑问,那么我会帮你

enjoy.happy编码。

Facebook的iOS SDK现在不提供这样的事情。 相反,我find了一个完全一样的东西的第三方类。 https://github.com/OceanLabs/FacebookImagePicker-iOS/