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.