facebook upload photo along with description and caption in iphone - 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

Related

Share text on Tumblr from ios application

In my application I want to share text via tumblr api.
I just want some hint on this so I can get exact idea on how to share text on tumblr.
Thanks
You can can use https://github.com/tumblr/TMTumblrSDK#authentication
i have shared text to tumblr with below code
NSArray* paramsKeys = [[NSArray alloc] initWithObjects:
#"title",
#"body",
nil];
NSArray* paramsVals = [[NSArray alloc] initWithObjects:
#"Testing",
#"HEllo Posting it to Tumblr",
nil];
NSDictionary *paramsDict = [[NSDictionary alloc]initWithObjects:paramsVals forKeys:paramsKeys];
[[TMAPIClient sharedInstance]text:#"blogname" parameters:paramsDict callback:^(id response, NSError *error)
{
if(!error)
{
NSDictionary *dashboard = response;
NSLog(#"%#",dashboard);
}
}];

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];

uploading image in facebook

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];

How to post a photos on facebook through iPhone app?

I am trying to post image on facebook but not successful yet,
my codes are:
- (void)postToWall{
int im = 1;
NSData *myimgData;
myimgData = [NSData dataWithContentsOfFile:saveImagePath];
//pstimg = myimgData;
NSArray *chunks = [pstimg componentsSeparatedByString: #"."];
NSString *atch= [chunks objectAtIndex: 0];
NSString *filePath = [[NSBundle mainBundle] pathForResource:atch ofType:#"jpg"];
img = [[UIImage alloc] initWithContentsOfFile:filePath];
//start
FBDialog* dialog = [[[FBStreamDialog alloc] init] autorelease];
NSString *str = #"Hello";
str = [str stringByReplacingOccurrencesOfString:#" " withString:#"+"];
dialog.cMessage=str;
dialog.userMessagePrompt = #"Enter your message:";
[dialog show];
NSData * findata;
//edited from here
if(im==1)
{
findata = myimgData;
}
else
{
findata = (NSData *)img;
}
NSMutableDictionary * param = [NSMutableDictionary dictionaryWithObjectsAndKeys:
img, #"picture",
nil];
FBRequest *uploadPhotoRequest =[FBRequest requestWithDelegate:self] ;
[uploadPhotoRequest call:#"facebook.photos.upload" params:param dataParam:myimgData];
[img release];
}
But it not posted.
To post a photo on Facebook you need to use the iOS SDK from Facebook:
https://github.com/facebook/facebook-ios-sdk
There you'll find sample app with authentication and much more, like posting a photo.

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,