iOS :How to get Facebook Album Photo's Picker
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.
How to get photos of a facebook album in iPhone SDK?
So /me/albums returns an array of Album objects, each of which has an id
.
If an album had an id of 99394368305, you can go to
https://graph.facebook.com/99394368305/photos
to get an array of photo objects.
Each of these will have the picture
and source
properties to get the image data from facebook.
They will all have an images
array as well if you want pre-scaled images instead of just the originals.
All the facebook queries give JSON back - I'm assuming that you know how to parse this?
iOS 8.3 Facebook SDK 4.1 Retrieve user's Profile Photo Album
There's no way to do this in one request as far as I know. You'll need to do two things:
Request the albums of the user, and parse the results for the album "Profile Pictures"
GET /me/albums?fields=id,name&locale=en_US
This returns an JSON like this:
{
"data": [
{
"id": "442898331243456464",
"name": "Profile Pictures",
"created_time": "2010-12-12T13:35:29+0000"
}
...
],
"paging": {
"cursors": {
"after": "NDQyODk4MzMxMjQz",
"before": "MTAxNTA5MjQyNDQ4NDYyNDQ="
}
}
}
Grab the
id
of the album with the name "Profile Pictures", and request thephotos
edge like this:GET /442898331243456464/photos
You will receive a JSON obect with the profile pictures. It's possible that you need to paginate through the results if there are more than 25 photos.
Images from facebook album
If you need to retrieve the images of a public album, then don't use GrabKit. GrabKit is made to retrieve the albums of the current logged user (on various platform as you mentioned) but not from public albums as you seem to wish.
I suggest you to use Facebook iOS SDK only.
Read their "get started" tutorial ( https://developers.facebook.com/docs/getting-started/facebook-sdk-for-ios/3.1/ ) and once you've figured out how to make a request to facebook, have a look to their Graph API ( https://developers.facebook.com/docs/reference/api/ ) and specially the page about "Album" ( https://developers.facebook.com/docs/reference/api/album/ )
I hope this helps :)
Pierre-Olivier Simonard - Developer of GrabKit
How to get photos from a facebook page without login in ios
This is the endpoint to get photos from a Page: https://developers.facebook.com/docs/graph-api/reference/page/photos/#Reading
You can use an App Access Token if the Page is not restricted by age or location - no login required. If the Page is restricted, you need to use a User Token of a User who is allowed to see the Page and its contents - or a Page Token if you manage the Page.
More information about Tokens:
- https://developers.facebook.com/docs/facebook-login/access-tokens
- http://www.devils-heaven.com/facebook-access-tokens/
Facebook iOS SDK: get album's cover picture
This is a bit strange but when I tried /<id>/picture
in the graph API explorer, it automatically appended ?redirect=false
to the request. And similar to your case, when I made a Graph API call to this edge from the Objective-C, it gave me null
. So getting a hint from the graph API explorer, I tried appending this param to my request which actually made it work. Try adding it and see if it works. So, in your case:
[NSString stringWithFormat:@"/%@/picture?redirect=false", album.coverPath]
The response looked something like this:
{
data = {
"is_silhouette" = 0;
url = "https://fbcdn-sphotos-f-a.akamaihd.net/hphotos...";
};
}
You can grab the url
field from data
here which should give you the cover photo.
Related Topics
Fast and Lean Pdf Viewer For Iphone/Ipad/Ios - Tips and Hints
Applications Are Expected to Have a Root View Controller At the End of Application Launch
Should Iboutlets Be Strong or Weak Under Arc
How to Force Nslocalizedstring to Use a Specific Language
How to Safely Delete Contents of Xcode Derived Data Folder
How to Debug 'Unrecognized Selector Sent to Instance' Error
Getting Error "No Such Module" Using Xcode, But the Framework Is There
The Simplest Way to Resize an Uiimage
How to Get Device Make and Model on Ios
How to Add Constraints Programmatically Using Swift
Uicollectionview Self Sizing Cells With Auto Layout
Attempt to Present Uiviewcontroller on Uiviewcontroller Whose View Is Not in the Window Hierarchy
Iphone Get Ssid Without Private Library
Dateformatter Doesn't Return Date For "Hh:Mm:Ss"