uploading image in facebook - iphone

While uploading image in facebook wall, image is not at all getting on the wall.
I tried:
[[FBRequest requestWithDelegate:self] call:#"facebook.Users.setStatus" params:
params dataParam:UIImagePNGRepresentation(img)];
to no avail.

You can do it using Sharekit....
Try this code...
-(void)shareOnFacebook {
//take screenshot
UIImage *image = "Your image";
//for debug purpose the image can be stored to photo album
//UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
SHKItem *fbItem = [SHKItem image:image title:#"Check out my Image!"];
[SHKFacebook shareItem:fbItem];
}

Using sharekit you can try following code:
-(IBAction)btnSendToFacebookPressed:(id)sender
{
NSString *var = [[NSUserDefaults standardUserDefaults] valueForKey:#"IMAGE_INDEX"];//This line may not be useful to you...
NSString *imageIndex = [[NSBundle mainBundle] pathForResource:var ofType:#"jpg"];
SHKItem *item = [SHKItem image:[UIImage imageWithContentsOfFile:imageIndex] title:#"Your Title"];
[NSClassFromString(#"SHKFacebook") performSelector:#selector(shareItem:) withObject:item];
}

Try to do it using Sharekit.
Add Sharekit framework to your project.
Change the setting from shkconfig.h file.
pass the key which you can generate from facebook->developer->apps->create new app->generate keys pass it to shkconfig.h
-(IBAction) tryItOnFb:(id)sender
{
SHKItem *item = [SHKItem image:[UIImage imageNamed:#"YES.png"]title:#"FB Test"];
[NSClassFromString(#"SHKFacebook") performSelector:#selector(shareItem:) withObject:item];
}

Images will get into your photo Album and information about it on the wall.
NSMutableDictionary *params =[NSMutableDictionary dictionaryWithObjectsAndKeys:#"Testmessage", #"message", imageData, #"picture", nil];
[facebook requestWithGraphPath:#"/me/photos" andParams:params andHttpMethod:#"POST" andDelegate:self];

Related

Image Post on Facebook?

In my application. I successfully post a image on my Facebook wall (image type JPEG Type). It's work fine in Simulator and and Device also.
But the problem is that When I Capture Image from my iPhone or select an image from library which is captured by camera. It is not Posted on Facebook Wall.
on other hand when i choose any jpeg image (downloaded by internet) from my iPhone library. It post on wall.
In my opinion there is image format problem. Please Guide me
Thanks
My code is here.
-(IBAction)clickButtonClicked
{
// For link post
NSString *Message = [NSString stringWithFormat:#"Testing Iphone App : \"http://www.google.com\" "];
DataClass *obj=[DataClass getInstance];
UIImage *image=[[UIImage alloc]init ];
image= obj.imgFinalImage;
NSMutableDictionary *params1 = [[NSMutableDictionary alloc]init];
[params1 setObject:image forKey:#"source"];
[params1 setObject:Message forKey:#"message"];
NSString *post=#"/me/photos";
[[appDelegate facebook] requestWithGraphPath:post andParams:params1 andHttpMethod:#"POST" andDelegate:self];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Message!" message:#"Invitation Send Sucessfully" delegate:self cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alert show];
[alert release];
}
My guess is that you pass the image in the wrong property:
NSMutableDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
sobj.imgFinalImage, #"picture",
Message, #"caption",
nil];
[[appDelegate facebook] requestWithMethodName:#"photos.upload"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
Then make sure you implement the delegate of Facbook request to check if the image is uploaded.
With the graph API you can't send a UIImage directly, you need to send the NSData representation of the UIImage:
NSMutableDictionary *params1 = [[NSMutableDictionary alloc]init];
NSData *imageDate = UIImagePNGRepresentation(obj.imgFinalImage);
[params1 imageDate forKey:#"source"];
[params1 setObject:Message forKey:#"message"];
NSString *post=#"/me/photos";
[[appDelegate facebook] requestWithGraphPath:post andParams:params1 andHttpMethod:#"POST" andDelegate:self];

sharing multiples items with sharekit on facebook

I know how to share an image lonely:
// Create a UIImage.
UIImage *image = [UIImage imageNamed:#"ShareKit.jpg"];
// Wrap the UIImage within the SHKItem class
SHKItem *item = [SHKItem image:image title:#"This image was sent with ShareKit!"];
// Create a ShareKit ActionSheet and Assign the Sheet an SHKItem
SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
// Display the ActionSheet in the current UIView
[actionSheet showInView:self.view];
and how to share a link lonely:
// Create an NSURL. This could come from anywhere in your app.
NSURL *url = [NSURL URLWithString:#"http://mobile.tutsplus.com"];
// Wrap the URL within the SHKItem Class
SHKItem *item = [SHKItem URL:url title:#"Mobiletuts!"];
// Create a ShareKit ActionSheet and Assign the Sheet an SHKItem
SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
// Display the ActionSheet in the current UIView
[actionSheet showInView:self.view];
but I don't know how to share both link and image in the same time. Can anyone help me on this?
You can do this one of two ways.
1. Through the URL property of SHKItem.
#property (nonatomic, retain) NSURL *URL;
Like so:
NSURL *url = [NSURL URLWithString:#"http://mobile.tutsplus.com"];
UIImage *image = [UIImage imageNamed:#"ShareKit.jpg"];
SHKItem *item = [SHKItem image:image title:#"This image was sent with ShareKit!"];
[item setURL:url];
2. Using the +[itemFromDictionary:] class method of SHKItem
+ (SHKItem *)itemFromDictionary:(NSDictionary *)dictionary;
Like so:
NSString *urlString = #"http://mobile.tutsplus.com";
UIImage *image = [UIImage imageNamed:#"ShareKit.jpg"];
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:urlString, #"URL", image, #"image", #"This image was sent with ShareKit!", #"title", nil];
SHKItem *item = [SHKItem itemFromDictionary:dictionary];
... and then sharing your item as desired. In your case, you can display using the -[actionSheetForItem:] method.

iPhone - sending an image with Sharekit to Facebook

I'm using ShareKit to send a comment and an image to facebook. Everything's working fine except that if no user image exists (in the coredata/sqlite db) I would like to send a default image instead. Here's my code, with example.png being the default image and initWithData:entity.userImage being the image the user added with their iPhone. Maybe there's something wrong with my if else statement.
-(IBAction) fbButton {
SHKItem *item;
NSURL *url = [NSURL URLWithString:#"http://itunes.apple.com/ae/artist/XXX"];
item = [SHKItem URL:url title:[NSString stringWithFormat:#"Take a look at %#", entity.name]];
[SHKFacebook shareItem:item];
if (entity.image = nil) {
UIImage *image = [UIImage imageNamed:#"example.png"];
SHKItem *item2 = [SHKItem image:image title:nil];
[SHKFacebook shareItem:item2];
} else {
UIImage *image = [[[UIImage alloc] initWithData:entity.userImage] autorelease];
SHKItem *item2 = [SHKItem image:image title:nil];
[SHKFacebook shareItem:item2];
}
[SHK flushOfflineQueue];
}
The problem is that if there is no image in the database Sharekit gives a UIAlert saying that a file must be present in the upload. I was trying to get around this by always providing a default image in case the record in the database doesn't have one.
as always, thanks for any help
USE if (entity.image == nil)
instead this if (entity.image = nil) {
if (imageView.image == nil) {
imageView.image = [UIImage imageNamed:#"fbicon.png"];
SHKItem *item2 = [SHKItem image:imageView.image title:#"Hi"];
[SHKFacebook shareItem:item2];
}
else {
SHKItem *item1 = [SHKItem image:imageView.image title:#"Hi"];
[SHKFacebook shareItem:item1];
}
UIImage *image = imageview.image
SHKItem *item;
item = [SHKItem image:image title:#"Hi"];
[NSClassFromString([NSString stringWithFormat:#"SHKFacebook"])
performSelector:#selector(shareItem:) withObject:item];

facebook upload photo along with description and caption in iphone

I want to upload the image to the facebook.
I could upload the photo along with caption. I also want to upload the description
I tried adding the key "description" to the dictionary. But it didn't work.
Is it possible to upload the description as well?
Following is the code i am using..
- (void)postToWall {
FBRequest *uploadPhotoRequest = [FBRequest request];
NSData* imageData = UIImageJPEGRepresentation(saveImage, 1.0);
UIImage *image_ = [[UIImage alloc] initWithData:imageData];
FBPermissionDialog* dialog1 = [[[FBPermissionDialog alloc] init] autorelease];
dialog1.delegate = self;
dialog1.permission = #"photo_upload";
[dialog1 show];
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"Hey!!!!!!", #"caption",
#"I Own It..", #"description", //This didn't post the description..
nil];
if (nil!=image_)
[uploadPhotoRequest call:#"photos.upload" params:params dataParam:(NSData*)image_];
NSLog(#"image uploaded");
[image_ release];
}
Have a look at this
http://www.raywenderlich.com/1488/how-to-use-facebooks-new-graph-api-from-your-iphone-app

How to send text and images using Facebook API in iPhone SDK?

In my iPhone app, I want to send text as well as images to facebook.
Currently the facebook API suggest that there are seperate user permissions that enable us to do so.
Is there a way out where in I can do both using only one API in my project?
If Yes, How can we do so?
References to any articles or tutorials would be very helpful
Please Help & Suggest.
Thanks
Yes you can do this.
Please have a look at all the methods as below:
- (IBAction)uploadPhoto:(id)sender {
[self postOnFacebook];
}
//Post Message and Photo on Facebook Function
-(void)postOnFacebook
{
NSString *strPostMessage = [self createMessageForPostOnFacebook:74.112 withLongitude:21.85];
//UIImage *img = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:objClsProductSearch.strProductImageURL]]];
//UIImage *img = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:#"http://www.facebook.com/images/devsite/iphone_connect_btn.jpg"]]];
UIImage *img = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:#"http://d1xzuxjlafny7l.cloudfront.net/wp-content/uploads/2011/08/HUDTutorial.jpg"]]];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
strPostMessage,#"message",img, #"source",
nil];
[_facebook requestWithGraphPath:#"/me/photos"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
[img release];
}
//Create Message for posting on Facebook
-(NSString *)createMessageForPostOnFacebook:(double)pfltLatitude withLongitude:(double)pfltLongitude
{
//NSString *urlString = [NSString stringWithFormat:#"http://maps.google.com/maps/geo?q=%f,%f&output=csv",pfltLatitude, pfltLongitude];
//NSString *urlString = [NSString stringWithFormat:#"http://maps.google.com/maps/geo?q=%f,%f&output=csv",#"", #""];
//NSError* error;
//NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString] encoding:NSASCIIStringEncoding error:&error];
//NSArray *listItems = [locationString componentsSeparatedByString:#","];
NSString *strMessage = nil;
/*if([[listItems objectAtIndex:0] isEqualToString:#"200"])
{
strMessage = [NSString stringWithFormat:#"I found a %# using BH for iPhone \n Location : %# \n Latitude : %f & Longitude : %f \n Product Rating : %d",objClsProductSearch.strCategoryname,[locationString substringFromIndex:6],appDelegate.dblLatitude,appDelegate.dblLongitude,btnTmp.tag];
}*/
strMessage = [NSString stringWithFormat:#"I found a %# using BH for iPhone \n Location : %# \n Latitude : %f & Longitude : %f \n Product Rating : %d", #"Cat Name", #"Location", 74.112, 21.85, 1];
return strMessage;
}
I hope you will have success using the above code.
Let me know in case of any difficulty.
In you app delegate, have a look at below methods whether it is implemented or not.
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
//return [[controller facebook] handleOpenURL:url];
//return [[objPage2ViewController facebook] handleOpenURL:url];
return [[[self.navigationController topViewController] facebook] handleOpenURL:url];
}
Cheers
I'm not sure that it is possible. I've post image with next solution:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
takedPhoto, #"picture",
#"some text", #"message",
nil];
[facebook requestWithGraphPath:#"/me/photos" andParams:params
andHttpMethod:#"POST" andDelegate:self];
takedPhoto is UIImage.
But it is only loading photos in photo album (and approve it if you allow permissions when logging in).
I don't know how can I post message on wall with this uploaded image...
Regards,