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];
Related
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to post photos to facebook iphone fbconnect
I am using FB SDK and getting an error while uploading picture on FB post from my app
in my view did load i have and UIImageView which has an image that i need to be posted on FB the code of the view did load
ImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 65, 65)];
ImageView.center = CGPointMake(42, 43);
[View addSubview:ImageView];
and in my method of FB post i did this
UIImage *image = [[UIImage alloc]init];
image = ImageView.image;
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:3];
[params setObject:#"LINK_HERE" forKey:#"link"];
// due to this line below, i am getting an error :
// "[UIImage length]: unrecognized selector sent to instance 0x170fa0e0"
// and if use http link instead of image(UIImage) it works, but i want to use my image
[params setObject:image forKey:#"picture"];
[params setObject:#"NAME_HERE" forKey:#"name"];
[params setObject:#"DEC_HERE" forKey:#"description"];
// Invoke the dialog
[self.facebook dialog:#"feed" andParams:params andDelegate:self];
How should i use my UIImage inside this code ... any idea ??
You can only upload URL based images in Facebook dialog method..Images generated within the app or within app bundle cant be uploaded..
To upload those images you have to use graph API
sample code
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
image, #"source",
#"caption desc", #"message",
nil];
[facebook requestWithGraphPath:[NSString stringWithFormat:#"/me/photos?access_token=%#", self.facebook.accessToken]
andParams:params andHttpMethod:#"POST" andDelegate:self];
you can post your image simply like this
UIImage *imgSource = {insert your image here};
NSString *strMessage = #"Images Description";
NSMutableDictionary* photosParams = [NSMutableDictionary dictionaryWithObjectsAndKeys:
imgSource,#"source",
strMessage,#"message",
nil];
[self.facebook requestWithGraphPath:#"me/photos"
andParams:photosParams
andHttpMethod:#"POST"
andDelegate:self];
There is a sample app in facebook sdk, please check that.
You can also check out these tutorials:
Facebook Tutorial for iOS: How To Use Facebook’s New Graph API from your iPhone App
Facebook Tutorial for iOS: How To Get a User Profile with Facebook’s New Graph API from your iPhone App
Facebook Tutorial for iOS: How To Post to a User’s Wall, Upload Photos, and Add a Like Button from your iPhone App
I want to post a link including an image to Facebook timeline:
UIImage *img = [UIImage imageNamed:#"1.png"];
self.postParams =
[[NSMutableDictionary alloc] initWithObjectsAndKeys:
#"Here we go", #"message",
#"https://developers.facebook.com/ios", #"link",
UIImagePNGRepresentation(img), #"picture",
#"Facebook SDK for iOS", #"name",
#"Build great social apps and get more installs.", #"caption",
#"The Facebook SDK for iOS makes it easier and faster to develop Facebook integrated iOS apps.", #"description",
nil];
[FBRequestConnection startWithGraphPath:#"me/feed" parameters:self.postParams HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
[self showAlert:#"Link is posted" result:result error:error];
}];
The UIImage does not posted. Can you help me?
But simply if I use :
#"https://developers.facebook.com/attachment/iossdk_logo.png", #"picture"
it works.
If you read the documentation, it says the "picture" parameter should be of type string ie: a url. You can not post an image and a message from the mobile SDKs at the same time without some clever hackory: see me/photos in the documentation but your options are severely limited.
I have upload images with url image successful on this way
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"https://developers.facebook.com/docs/reference/dialogs/", #"link",
#"http://fbrell.com/f8.jpg", #"picture",
#"Facebook Dialogs", #"name",
#"Reference Documentation", #"caption",
#"Using Dialogs to interact with users.", #"description",
nil];
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[[delegate facebook] dialog:#"feed"
andParams:params
andDelegate:self];
Now i want to upload image from a local image in same way
like
profImg = [UIImage imageNamed:LoginWithFacebookNormal#2x.png"];
NSData *data = [NSData dataWithData:UIImagePNGRepresentation(profImg)];
i have used data, #"picture", in dictionary but it's give me error
is it any other way to upload local/Gallery/resource image with dialog box + comment area ?
I have searched but every time found that only url image can feed the dialog box
I have used Hackgraph tutorial for this posting.
Note: I am not using Sharekit or any other API i have used only Graph API
Finally after lots of research I get the example of Facebook. Download the example from here. You have to make modification because currently example hold static image.
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];
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];