Facebook iOS SDK是否提供任何默认(Facebook)相册照片的选择器UIImagePickerController
?
我听说过这么长时间搜索它但却找不到任何东西。
如果有人对此有任何想法,请告诉我。如果不是,那么我肯定需要自己制作。
答案 0 :(得分:24)
从Facebook导入
没有第三方工具的从专辑中获取Facebook照片工作图pi 2.4,2.5,2.6,2.7,2.8& Facebook图表api 2.10
1)在Facebook开发者帐户中添加应用
2)然后在app中选择平台以便更好地理解以下屏幕截图
3)选择ios&按照向导中的所有步骤显示
4)然后转到图api探索https://developers.facebook.com/tools/explorer/145634995501895/
5)在图形api explorer中选择你的应用程序了解更多了解显示屏幕截图
6)点击获取令牌..然后点击获取令牌中的获取访问令牌,您可以看到很多权限,以便更好地了解图像
7)用于获取或关闭获取专辑名称的权限。图像显示在屏幕截图之后
如果未启用user_photos权限,则显示错误,请参阅以下屏幕截图
完成步骤7后,请执行以下步骤或只下载编码文件。我已经把链接放在哪里可以下载
为目标c编码文件
https://www.dropbox.com/s/1ysek035ek88xuw/FacebookAlbum%20Demo.zip?dl=0
8)如果没有错误显示,则在视图controller的 viewDidLoad 方法中执行以下代码。此代码用于获取相册名称&专辑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)现在在行查看表格单元格
中获取代码类型后的专辑封面照片目标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)现在用于获取相册照片的代码。
// 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编码。
答案 1 :(得分:2)
Facebook iOS SDK目前还没有提供此类功能。相反,我找到了一个完全相同的第三方课程。 https://github.com/OceanLabs/FacebookImagePicker-iOS/