I need to get profile picture from profile album only.
I know how to get profile picture directly from userId and i know how to get the photos of album.
the problem is -
I need to get all the photos from profile album and need to set the profile picture on first position.
If i get the profile picture directly from userId and after that i place the profile album photos then the profile picture will repeat twice because it's in album too.
So, i need some solution like i'll identify the profile picture from profile album.
any link,tutorial,suggestion,idea will be great help.
Update
This will definitely help you.
[FBRequestConnection startWithGraphPath:#"me?fields=albums.fields(name,photos.fields(name,picture,source))"
parameters:nil
HTTPMethod:#"GET"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
//NSLog(#"result %#",result);
NSString * anImage;
NSArray* albums = result[#"albums"][#"data"];
NSUInteger index = [albums indexOfObjectPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
return [obj[#"name"] isEqualToString: #"Profile Pictures"];
}];
if (index != NSNotFound) {
NSDictionary *profileImages = albums[index];
NSDictionary *photos = profileImages[#"photos"];
NSArray *data = photos[#"data"];
for (NSDictionary *picture in data) {
NSString *date = picture[#"created_time"];
NSString *id = picture[#"id"];
NSString *pictureUrl = picture[#"picture"];
NSString *sourceUrl = picture[#"source"];
}
}
}];
The reply above (below once I added my reply) helps me. I upvote, the updated solution for SDK V4:
[[[FBSDKGraphRequest alloc] initWithGraphPath:#"me" parameters:#{#"fields": #"albums.fields(name,photos.fields(name,picture,source,created_time))"}]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
//NSLog(#"result %#",result);
NSString * anImage;
NSArray* albums = result[#"albums"][#"data"];
NSUInteger index = [albums indexOfObjectPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
return [obj[#"name"] isEqualToString: #"Profile Pictures"];
}];
if (index != NSNotFound) {
NSDictionary *profileImages = albums[index];
NSDictionary *photos = profileImages[#"photos"];
NSArray *data = photos[#"data"];
for (NSDictionary *picture in data) {
NSString *date = picture[#"created_time"];
NSString *id = picture[#"id"];
NSString *pictureUrl = picture[#"picture"];
NSString *sourceUrl = picture[#"source"];
}
}
}];
Related
I am making in app in which i show user's hometown,location on profile screen. I get the required data when using developer's account and get data for every user when current user is looking at its own profile.
But when i try to look at other's profile, i don't get the desired data. Here is my code for how i am getting the data out.
-(void)loadFbData{
NSMutableString *graphPath = [NSMutableString stringWithFormat:#"/?id=%#",[self.user valueForKey:#"facebookId"]];
[graphPath appendString:#"&fields=location,hometown,picture.width(640).length(342),name,gender,email,website"];
[FBRequestConnection startWithGraphPath:graphPath completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
dispatch_async(dispatch_get_main_queue(), ^{
self.personalDataView.webLabel.text = [result objectForKey:#"website"];
self.personalDataView.emailLabel.text = [result objectForKey:#"email"];
self.personalDataView.webLabel.text = [result valueForKey:#"website"];
self.profileBasicDataView.livesInLbl.text = [[result objectForKey:#"location"] objectForKey:#"name"];
self.profileBasicDataView.fromLbl.text = [[result objectForKey:#"hometown"] objectForKey:#"name"];
});
NSURL *url = [NSURL URLWithString:[[result objectForKey:#"picture"] valueForKeyPath:#"data.url"]];
[self.profileBasicDataView loadUserFbData:result];
[self.profileImage loadImage:url];
}
}];
}
**website and email is hidden when other user's profile is shown.
i'm trying to retrieve the current users birthday through FBRequestConnection. i've successfully retrieved id, name and gender, but birthday just returns null. Why and what can i do in order to get the current users birthday? do i need some kind of permisson?
[FBRequestConnection
startForMeWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSString *facebookId = [result objectForKey:#"id"];
NSString *facebookName = [result objectForKey:#"name"];
NSString *birthday = result[#"birthday"];
NSString *gender = result[#"gender"];
NSLog(#"%#", birthday);
}
}];
loginButton = [[FBSDKLoginButton alloc] init];
loginButton.frame = CGRectMake(self.view.frame.size.width/2-loginButton.frame.size.width, self.view.frame.size.height/2+100, 250, 20);
loginButton.readPermissions=#[#"email",#"user_birthday"];
try to add code above.
I am stuck with getting picture from Facebook Graph API for news feed with small size. This is the url I get https://fbcdn-photos-b-a.akamaihd.net/hphotos-ak-xpf1/t1.0-0/10363492_10202184985725870_7374705736674502849_s.jpg. Not sure how will get the picture with size o.jpg
Finally, figured it out. Here is what I did.
NSString *query = [NSString stringWithFormat:#"SELECT pid, object_id, src_big, src_big_width, src_big_height FROM photo WHERE object_id = %#", wallPost[#"object_id"]]; //begins from SELECT........
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
query, #"q",
nil];
[FBRequestConnection startWithGraphPath:#"/fql" parameters:params HTTPMethod:#"GET" completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
//do your stuff
if (!error) {
NSArray *photo = [result objectForKey:#"data"];
NSString *photoString = [[photo valueForKey:#"src_big"]componentsJoinedByString:#""];
//NSLog(#"result %# %#", photoString);
}
}];
I am trying to create a new album on a user's Facebook account, and upload images to that album. I have succeeded to create an album, but when I start uploading images to it only the last image selected gets uploaded the number of times the images I have selected.
This is my piece of code to create a Facebook album and upload images to it
- (void)createFacebookAlbum {
NSMutableDictionary* parameters = [NSMutableDictionary dictionary];
[parameters setObject:albumNAME forKey:#"name"];
[parameters setObject:#"Test message" forKey:#"message"];
FBRequest* request = [FBRequest requestWithGraphPath:#"me/albums" parameters:parameters HTTPMethod:#"POST"];
NSLog(#"creating facebook album");
FBRequestConnection *connection = [[FBRequestConnection alloc] init];
[connection addRequest:request
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
albumId = [result objectForKey:#"id"];
NSLog(#"OK %#", albumId);
[self publishContentToAlbum:[result objectForKey:#"id"]];
}
else {
NSLog(#"Error: %#",error.userInfo);
}
}];
[connection start];
}
-(void)uploadBulkPhotosToAlbum:(NSMutableArray *)photoArray albumId:(NSMutableArray *)albumId{
FBRequestConnection *connection = [[FBRequestConnection alloc] init];
NSString *graphPath = [NSString stringWithFormat:#"%#/photos",albumId];
NSMutableString *jsonFormat = [[NSMutableString alloc] init];
[jsonFormat setString:#"["];
for (int i = 0; i < (NSUInteger *)countere; i++)
{
if (i != 0)
{
[jsonFormat appendString:#","];
}
NSString *fileName = [NSString stringWithFormat:#"file%d",i];
NSString *jsonRequest = [NSString stringWithFormat:#"{ \"method\": \"POST\", \"relative_url\": \"%#\", \"attached_files\": \"%#\" }",graphPath,fileName];
[jsonFormat appendString:[NSString stringWithFormat:#" %#",jsonRequest]];
}
[jsonFormat appendString:#" ]"];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:jsonFormat,#"batch",nil];
for (int i = 0; i <(NSUInteger *)countere; i++)
{
NSString *fileName = [NSString stringWithFormat:#"file%d",i];
NSData *data = UIImagePNGRepresentation([photoArray objectAtIndex:i]);
[params setObject:data forKey:fileName];
}
FBRequest *request1 = [FBRequest requestWithGraphPath:graphPath
parameters:params
HTTPMethod:#"POST"];
[connection addRequest:request1
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSLog(#"Photo uploaded successfuly! %#",result);
} else {
NSLog(#"Photo uploaded failed :( %#",error.userInfo);
}
}];
[connection start];
}
Can anyone help me to solve my problem?
Thanks for the reply.
I work on facebook graph api. And I've allready get the id of users which have using my app. I can display the id of users and what I want to do , It's display in each cell of my tableview a FBProfilePictureView for the good user.
[[FBRequest requestForMe] startWithCompletionHandler:
^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if (!error) {}
NSString* fql =
#"SELECT uid FROM user WHERE is_app_user=true AND uid IN (SELECT uid2 FROM friend WHERE uid1 = me())";
[FBRequestConnection startWithGraphPath:#"/fql"
parameters:#{ #"q" : fql}
HTTPMethod:#"GET"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
FBRequest *fql = [FBRequest requestForGraphPath:#"fql"];
[fql.parameters setObject:#"SELECT uid,name,is_app_user FROM user WHERE is_app_user AND uid IN (SELECT uid2 FROM friend WHERE uid1 = me())" forKey:#"q"];
[fql startWithCompletionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
if (result) {
NSArray *arrayRsult = [result objectForKey:#"data"];
NSMutableArray *ids = (NSMutableArray *) [arrayRsult valueForKey:#"uid"];
NSMutableArray *names = (NSMutableArray *) [arrayRsult valueForKey:#"name"];
recentFriends = [[NSMutableArray alloc] init];
idFriends = [[NSMutableArray alloc] init];
for (NSDictionary *c in ids)
{
[idFriends addObject:c];
}
arrayLength = [recentFriends count];
NSLog(#"ids are : %# ",idFriends);
NSLog(#"there are %i", arrayLength);
I 've allready done , to begin , display my facebook profile picture in each cell with this code :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
FBProfilePictureView *prof = [[FBProfilePictureView alloc]initWithFrame:CGRectMake(5, 5, 30, 30)];
[[FBRequest requestForMe] startWithCompletionHandler:
^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if (!error) {
prof.profileID = [user objectForKey:#"id"];
}
}];
[cell addSubview:prof];
}
I don't use custom cell and nib for custom cells.
I don't know how to create an array for this table.
I've tried this code cell.imageView.image = [idFriends objectAtIndex:indexPath.row];
(idFriends is declared in the .h file as __block NSMutableArray )
Thanks for your help !
yes, you can display profile picture of user in UITableViewCell, you can use default ImageView of Cell. You can get profile picture of user with its Facebook ID as following..
To get Small/Thumb Image of Profile use
http://graph.facebook.com/<Friends Facebook ID>/picture?type=small
You can also try following parameters in type, normal, large, square
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:#"http://graph.facebook.com/517267866/picture?type=small"]];
UIImage *profilePic = [UIImage imageWithData:imageData];
Given code will grab the image from URL and assign that UIImage to your UIImageView
if you want more detail about it please just Read Documentation here
cell.imageView.image = profilePic;
Actually using "http://graph.facebook.com//picture?type=small" to fetch the profile image of the user or even their friends is slow.
A better and faster way of doing it to add a FBProfilePictureView object to your view and in it's profileID property, assign the user's Facebook id.
For example:
FBProfilePictureView *friendsPic;
friendsPic.profileID = #"1379925668972042";