iOS :如何获取Facebook相册照片的选择器
iOS :How to get Facebook Album Photo's Picker
Facebook iOS SDK 是否提供任何默认 (Facebook) 相册照片的选择器,就像 UIImagePickerController
一样?
我听说过这个,所以搜索了很长时间,但找不到任何东西。
如果有人对此有任何想法,请告诉我。如果不是,那我肯定需要自己做。
Facebook iOS SDK 目前不提供此类功能。相反,我找到了第三方 class 做完全相同的事情。 https://github.com/OceanLabs/FacebookImagePicker-iOS/
从 Facebook 导入
没有第三方工具从相册Working For graph api 2.4, 2.5, 2.6,2.7,2.8 & Facebook graph api 2.10
1) 在 Facebook 开发者帐户中添加应用程序
2) 然后在应用程序中选择平台以便更好地理解,请参见以下屏幕截图
3) 选择 ios 并按照向导中的所有步骤显示进行操作
4) 然后转到图表 api 探索 https://developers.facebook.com/tools/explorer/145634995501895/
5)select 你在图表中的应用 api explorer 更多了解显示屏幕截图
6) 点击 Get token ..然后在 get token 中点击 get access token 你可以看到这么多权限以便更好地理解看图片
7) 打开或关闭检查您的权限以在屏幕截图后显示相册名称和图像
如果 user_photos 权限未打开则显示错误,请参见以下屏幕截图
完成第 7 步后,请执行以下步骤或仅下载编码文件。我已经把 link 放在哪里你可以下载
objective c
的编码文件
https://www.dropbox.com/s/1ysek035ek88xuw/FacebookAlbum%20Demo.zip?dl=0
8) 如果没有错误显示,那么在 viewDidLoad 方法中的以下代码在视图 controller.this 代码中用于获取相册名称和相册 ID。
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) 现在在 tableview 单元格行 中输入代码后获取相册封面照片
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)现在是获取相册照片 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) 另一个视图控制器现在用于在 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) 获取数据后你必须在facebook提交你的应用程序提交你可以在
填写信息
1)应用详情
2)状态和评论
=====
如果你有任何疑问,我会帮助你
enjoy.happy编码。
Facebook iOS SDK 是否提供任何默认 (Facebook) 相册照片的选择器,就像 UIImagePickerController
一样?
我听说过这个,所以搜索了很长时间,但找不到任何东西。
如果有人对此有任何想法,请告诉我。如果不是,那我肯定需要自己做。
Facebook iOS SDK 目前不提供此类功能。相反,我找到了第三方 class 做完全相同的事情。 https://github.com/OceanLabs/FacebookImagePicker-iOS/
从 Facebook 导入
没有第三方工具从相册Working For graph api 2.4, 2.5, 2.6,2.7,2.8 & Facebook graph api 2.10
1) 在 Facebook 开发者帐户中添加应用程序
2) 然后在应用程序中选择平台以便更好地理解,请参见以下屏幕截图
3) 选择 ios 并按照向导中的所有步骤显示进行操作
4) 然后转到图表 api 探索 https://developers.facebook.com/tools/explorer/145634995501895/
5)select 你在图表中的应用 api explorer 更多了解显示屏幕截图
6) 点击 Get token ..然后在 get token 中点击 get access token 你可以看到这么多权限以便更好地理解看图片
7) 打开或关闭检查您的权限以在屏幕截图后显示相册名称和图像
如果 user_photos 权限未打开则显示错误,请参见以下屏幕截图
完成第 7 步后,请执行以下步骤或仅下载编码文件。我已经把 link 放在哪里你可以下载
objective c
的编码文件https://www.dropbox.com/s/1ysek035ek88xuw/FacebookAlbum%20Demo.zip?dl=0
8) 如果没有错误显示,那么在 viewDidLoad 方法中的以下代码在视图 controller.this 代码中用于获取相册名称和相册 ID。
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) 现在在 tableview 单元格行 中输入代码后获取相册封面照片
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)现在是获取相册照片 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) 另一个视图控制器现在用于在 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) 获取数据后你必须在facebook提交你的应用程序提交你可以在
填写信息1)应用详情
2)状态和评论
=====
如果你有任何疑问,我会帮助你
enjoy.happy编码。