Not receiving Facebook picture via Graph API - iphone

I can't seem to properly retrieve a user's profile picture using the current iOS graph method.
My call: self.pictureRequest = [facebook requestWithGraphPath:#"me/picture" andDelegate:self];
What I do with the result:
-(void)request:(FBRequest *)request didLoad:(id)result{
if(request == self.pictureRequest){
UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
image.image = [UIImage imageWithData:result];
[self.view addSubview:image];
NSLog("result is %#", result);
}
So I'm just trying to get the profile picture right now. Result shows up as null in the console. I guess this means I'm not actually getting a result? (I tried if(result) NSLog(#"got a result") but it doesn't return, so I'm guessing a result isn't being sent back by fb?)
Any ideas? I also looked up a similar problem here but not sure what they do differently:
Problem getting Facebook pictures via iOS

well I can retrieve the user pic and other info like this .. try it
- (void)fetchUserDetails {
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"SELECT uid, name, pic, email FROM user WHERE uid=me()", #"query",nil];
[fb requestWithMethodName:#"fql.query"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
}//Call this function after the facebook didlogin
and in request didLoad:
- (void)request:(FBRequest *)request didLoad:(id)result
{
if([request.url rangeOfString:#"fql.query"].location !=NSNotFound)
{
if ([result isKindOfClass:[NSArray class]] && [result count]>0) {
result = [result objectAtIndex:0];
}
if ([result objectForKey:#"name"]) {
self.fbUserName = [result objectForKey:#"name"];
// Get the profile image
UIImage *fbimage = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[result objectForKey:#"pic"]]]];
}

If you want to get the picture URL using requestWithGraph path (instead of requestWithMethodName like #Malek_Jundi provides) then see my answer here:
iOS Facebook Graph API Profile picture link

You can also get fb profile picture url by,
NSString *userFbId;
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"https://graph.facebook.com/%#/picture", userFbId]];
NSData *imageData = [[NSData alloc] initWithContentsOfURL:url];
self.userProfileImage.image = [UIImage imageWithData:imageData];

Related

Post image from local machine to user wall of Facebook

How can i post images using slRequest to Facebook user wall ?
-(IBAction)done
{
NSString *message=#"hello";
NSString *picture=[[NSBundle mainBundle]pathForResource:#"4" ofType:#"jpg"];
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:message, #"message",picture,#"picture", nil];
}
Try to use this one and you know you are getting path from NSBundle not image so you need to get first image from picture path and then do it.
NSString *picture=[[NSBundle mainBundle]pathForResource:#"4" ofType:#"jpg"];
UIImage *image = [UIImage imageWithContentsOfFile:picture];
NSMutableDictionary* params = [[NSMutableDictionary alloc] initWithObjectsAndKeys:message, #"message",image, #"picture",nil];
try this,use #"source" key for post image
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:_image, #"source",msg,#"name",nil];
//_image is UIImage

Getting image from gallery of Facebook and show it in iPhone

I want get image from public perfil of Facebook and show it in my iPhone. I'm using the Facebook Developer method "getPhoto" but I canĀ“t show any image?
Can someone help me?
NSString *url = [[NSString alloc] initWithFormat:#"https://graph.facebook.com/%#/picture",objectID];
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:url]]];
As told Previously your problem to retrieve the object id. Here is the solution:-
To retrieve the images of your friend. Create the connection with the url
NSString *url = [[NSString alloc] initWithFormat:#"https://graph.facebook.com/me/friends?access_token=%#",accessTokenValue];
above url when hit returns an array of dictionary in which name of your friend and his id is written. Just Json parse that you will get the id of the person.
you need to use graph api for this purpose
NSString *url = [[NSString alloc] initWithFormat:#"https://graph.facebook.com/%#/picture",objectID];
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:url]]];

FBConnect iphone : I coud'nt get Photos albums for some account ?

Maybe someone can't help me.
I use the last FBConnect (http://github.com/facebook/facebook-ios-sdk/) for Facebook connexion.
And I retreive the list of photos albums for the user.
NSMutableDictionary* params = [NSMutableDictionary NictionaryWithObjectsAndKeys:_facebook.accessToken,#"access_token",nil];
[_facebook requestWithGraphPath:#"me/albums" andParams:params andDelegate:self];
I'm testing with 4 differents account with all the same rules for privacy (Account/Privacy settings). And for some of them the albums list is empty ? And if i test via a webbrowser on a desktop computer (https://graph.facebook.com/me/albums) for account who doesn't work on iphone, the list is not empty ?
On iphone, i use graph api or FQL with same results ("SELECT aid FROM album WHERE owner = me()")
Maybe i miss some think about configuration off the facebookapp ?
Thanks for answer.
I resolve the solution with good settings for facebook authentifications
http://developers.facebook.com/docs/authentication/permissions
THIS WILL PUT ALL THE IMAGES OF THE ALBUM IN SOURCE ARRAY!
NSURL *url1 = [NSURL URLWithString:[NSString stringWithFormat:#"https://graph.facebook.com/%#/photos&access_token=AAACeFkezepQBANpoFq9I3Hts0JdE6Xis3UpZBqNxpgw62zWSlhSYyYcluGaaxH3IlKIh9w8OYrXYF9MsAxhk6ta1ANZClCaznpdSaERgZDZD",A_ID]];
URLWithString:#"https://graph.facebook.com/114750591966408/photos&access_token=//AAACeFkezepQBANpoFq9I3Hts0JdE6Xis3UyYcluGaaxH3IlKIh9w8OYrXYF9MsAxhk6ta1ANZClCaznpdSaERgZDZD"];
NSData *data1 = [NSData dataWithContentsOfURL:url1];
NSString *str1=[[NSString alloc] initWithData:data1 encoding:NSASCIIStringEncoding];
// NSString *str1=[[NSString alloc]ini]
NSDictionary *userData1 = [str1 JSONValue];
NSArray *arrOfimages=[userData1 objectForKey:#"data"];
NSMutableArray *sourceUrls = [[NSMutableArray alloc] initWithCapacity:0];
for(NSDictionary *subDictionary in arrOfimages)
{
[sourceUrls addObject:[subDictionary objectForKey:#"picture"]];
}
publish_actions and user_photos permissions is required.
And then please try the following code :
[FBRequestConnection startWithGraphPath:#"me/albums"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
// Success! Include your code to handle the results here
NSLog(#"user events: %#", result);
NSArray *feed =[result objectForKey:#"data"];
for (NSDictionary *dict in feed) {
NSLog(#"first %#",dict);
}
} else {
// An error occurred, we need to handle the error
// Check out our error handling guide: https://developers.facebook.com/docs/ios/errors/
NSLog(#"error %#", error.description);
}
}];

FBConnect - uploading images to Wall

i've configured FBConnect and it uploads to the wall, but what i want to do is take a screenshot and then upload the screenshot to FB.
In the below code there is an image but as a url. Can i intersect this and put in my screenshot image?
FBStreamDialog *dialog = [[[FBStreamDialog alloc] init]autorelease];
dialog.userMessagePrompt = #"Tell your friends about Fridgit!!:";
dialog.attachment = [NSString stringWithFormat:#"{\"name\":\"Facebook Connect for iPhone\",\"href\":\"http://developers.facebook.com/connect.phptab=iphone\",\"caption\":\"Caption\",\"description\":\"Description\",\"media\":[{\"type\":\"image\",\"src\":\"screenShot\",\"href\":\"http://developers.facebook.com/connect.php?tab=iphone/\"}],\"properties\":{\"another link\":{\"text\":\"Facebook home page\",\"href\":\"http://www.facebook.com\"}}}", self.screenShot];
[dialog show];
}
i know all the code is default i haven't edited it yet incase i can't do what i want to do.
Cheers
Yes its possible with the new FB API nw, they made it as simple as possible
// code snippet to take a snapshot
// REF: http://stackoverflow.com/questions/2200736/how-to-take-a-screenshot-programmatically
UIGraphicsBeginImageContext(self.window.bounds.size);
[self.window.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
img, #"picture",
nil];
[_facebook requestWithGraphPath:#"me/photos"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];

How to post images with text in facebook integration in Iphone sdk

Here Iam having a problem.Actually I implemented the facebook integration in my application and I need to post the images with text but I dont have any idea how to work on this.can anyone suggest this with a sample code so that it is very helpful for me.
Anyone's help will be much appreciated.
I assume that you want to draw some text in an image, and then upload the image to Facebook.
At first, we need to draw the original image and the desired text into a new image.
UIGraphicsBeginImageContext(CGSizeMake(320.0, 320.0));
CGContextRef context = UIGraphicsGetCurrentContext();
// Draw the original image
[image drawInRect:CGRectMake(0, 0, 320.0, 320.0)];
// Draw the text
[#"text" drawInRect:CGRectMake(...) withFont:[UIFont systemFontOfSize:20.0];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
And then, convert the image into NSData and call Facebook's "photos.upload" API to upload it.
NSMutableDictionary *args = [[[NSMutableDictionary alloc] init] autorelease];
[args setObject:#"caption" forKey:#"caption"];
FBRequest *uploadPhotoRequest = [FBRequest requestWithDelegate:self];
NSData *data = UIImagePNGRepresentation(newImage);
[uploadPhotoRequest call:#"photos.upload" params:args dataParam:data];
If you want to upload the images to your server, and post a small story to Facebook's wall. Use the stream API.
FBStreamDialog *dialog = [[[FBStreamDialog alloc] init] autorelease];
dialog.delegate = self;
dialog.userMessagePrompt = #"Prompt";
NSString *name = #"Your caption";
NSString *src = #"http://example.com/path/of/your/image";
NSString *href = #"http://what/happens/if/the/user/click/on/the/image";
NSString *attachment = [NSString stringWithFormat:#"{\"name\":\"%#\",\"media\":[{\"type\":\"image\", \"src\":\"%#\", \"href\":\"%#\"}]}", name, src, href];
dialog.attachment = attachment;
[dialog show];
Maybe you would be happy using BMSocialShare. It's a simple lib I wrote.
BMFacebookPost *post = [[BMFacebookPost alloc]
initWithTitle:#"Simple sharing via Facebook, Email and Twitter for iOS!"
descriptionText:#"Posting to Facebook, Twitter and Email made dead simple on iOS. Simply include BMSocialShare as a framework and you are ready to go."
andHref:#"https://github.com/blockhaus/BMSocialShare"];
[post setImageUrl:#"http://www.blockhausmedien.at/images/logo-new.gif"
withHref:#"http://www.blockhaus-media.com"];
[[BMSocialShare sharedInstance] facebookPublish:post];