upload image on facebook ios - iphone

please help me to upload image on facebook using iphone app.here i dont have the url.i just only have the image.but i cant upload it on face book.if i can use an url then i can simply upload it.please help me.
please send me the code for upload image.
i already create facebook instance and other codes relative to fbconnect ios.

The DemoApp that comes with the facebook ios api contains the code to upload a photo in the sample:
https://github.com/facebook/facebook-ios-sdk/tree/master/sample/DemoApp
/**
* Upload a photo.
*/
- (IBAction)uploadPhoto:(id)sender {
NSString *path = #"http://www.facebook.com/images/devsite/iphone_connect_btn.jpg";
NSURL *url = [NSURL URLWithString:path];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[UIImage alloc] initWithData:data];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
img, #"picture",
nil];
[_facebook requestWithMethodName:#"photos.upload"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
[img release];
}

Related

Share image from bundle and link on Facebook in iphone

I want to share image,link etc to Facebook from my iphone app.My app Link,cation,name and description posted successfully. But i can't share image. Please follow my code..
UIImage *image = [UIImage imageNamed:#"sample.png"];
NSData *imgData = UIImageJPEGRepresentation(image, 1.0);
self.dictionary =[[NSMutableDictionary alloc] initWithObjectsAndKeys: #"https://www.google.com/ios", #"link",
imgData, #"data",
#"AppName", #"name",
#"Testing", #"caption",
#"say something about this", #"description",
nil];
my share facebook code is..
[facebook requestWithGraphPath:#"/me/feed" andParams:dictionary andHttpMethod:#"POST" andDelegate:self];
My problem is how to take image from bundle and how to share selected image to Facebook?Please help me..
use like below:
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"image1" ofType:#"png"];
NSData *videoData = [NSData dataWithContentsOfFile:filePath];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"My hat image", #"message", data, #"source", nil];
[facebook requestWithGraphPath:#"/me/photos" andParams:params andHttpMethod:#"POST" andDelegate:self];

How To Get Friends Profile Pic in fb

FB_Graph_Response = [FB_Graph doGraphGet:#"me/friends" withGetVars:nil];
// NSLog(#"%#",[FB_Graph_Response.htmlResponse JSONValue]);
arrFriendsList = [[[FB_Graph_Response.htmlResponse JSONValue]objectForKey:#"data"]retain];
I have accessed the friends list in my app by using fb graph api(above request),
but i am not able to get friend's profile images. how to get it?
Get the id (or the nick) of the user, and get the picture from https://graph.facebook.com/idOrNick/picture
This works without any kind of auth.
Small sample:
NSString id = getTheIdOrNick;
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"https://graph.facebook.com/%#/picture", id]];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:data];
//UIImageView *imgView = [[UIImageView alloc]init];
//imgView.image = image;

How to upload .mp4 video on facebook using graph api in objective c

I am using Graph API to upload video on facebook. I am able to upload .wmv format video but not .mp4. My code is as below
strVidUrl=#"http://myshow.com.au/Videos/mp4s/20111216044530271247467.mp4";
//strVidUrl=#"http://www.myshow.com.au/Videos/BossAlarm.wmv";
NSURL *url = [NSURL URLWithString:strVidUrl];
NSData *data = [NSData dataWithContentsOfURL:url];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
data, #"video.mov",
#"video/mp4", #"contentType",
[dicVideoDetails valueForKey:#"fld_display_name"], #"title",
[dicVideoDetails valueForKey:#"fld_video_description"], #"description",
nil];
if I use .wmv then code is below and it is running.
NSURL *url = [NSURL URLWithString:#"http://www.myshow.com.au/Videos/BossAlarm.wmv"];
NSData *data = [NSData dataWithContentsOfURL:url];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
data, #"video.mov",
#"video/quicktime", #"contentType",
#"Video Test Title", #"title",
#"Video Test Description", #"description",
nil];
Result is comming same in both cases but .mp4 video is not showing on facebook. while .wmv is showing there.
Please help me.
That may be due to the missmatch of codecs and compression rates of your source video and fb's recomented video format
Check the following Links
Upload Video on facebook
demo
Regards,
Let me know in case of queries.

Framework for uploading images with titles to Facebook

I see in the internet codes that do upload images but the use "Facebook" that isn't recognized, so which framework do I need to use in iOS?
Do you have a code example?
I found this code:
- (IBAction)uploadPhoto:(id)sender {
NSString *path = #"http://www.facebook.com/images/devsite/iphone_connect_btn.jpg";
NSURL *url = [NSURL URLWithString:path];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[UIImage alloc] initWithData:data];
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:img, #"picture", #"my photo's caption text here.", #"message", nil];
[facebook requestWithMethodName: #"photos.upload" andParams:params andHttpMethod:#"POST" andDelegate:self];
[img release];
}
You'll need to add the Facebook iOS SDK to your project.
All the details you need should be found here

How to Upload Photos on facebook using Graph API in iPhone?

I have made one application, In my application I have integrate Facebook for sharing information.
for Facebook integration I have use Graph API in application.
now In my application, I want to upload photo on user's wall.
I have use this code for upload photo on user's wall.
// for upload photo
- (void)uploadPhoto:(id)sender {
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"Image1" ofType:#"jpg"];
NSString *message = [NSString stringWithFormat:#"I think this is a Great Image!"];
NSURL *url = [NSURL URLWithString:#"https://graph.facebook.com/me/photos"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request addFile:filePath forKey:#"file"];
[request setPostValue:message forKey:#"message"];
[request setPostValue:_accessToken forKey:#"access_token"];
[request setDidFinishSelector:#selector(sendToPhotosFinished:)];
[request setDelegate:self];
[request startAsynchronous];
}
- (void)sendToPhotosFinished:(ASIHTTPRequest *)request {
// Use when fetching text data
NSString *responseString = [request responseString];
NSMutableDictionary *responseJSON = [responseString JSONValue];
NSString *photoId = [responseJSON objectForKey:#"id"];
NSLog(#"Photo id is: %#", photoId);
NSString *urlString = [NSString stringWithFormat:
#"https://graph.facebook.com/%#?access_token=%#", photoId,
[_accessToken stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSURL *url = [NSURL URLWithString:urlString];
ASIHTTPRequest *newRequest = [ASIHTTPRequest requestWithURL:url];
[newRequest setDidFinishSelector:#selector(getFacebookPhotoFinished:)];
[newRequest setDelegate:self];
[newRequest startAsynchronous];
}
But, here I get
responseString is {"error":{"message":"Error validating application.","type":"OAuthException"}} and
Photo id is: (null)
and Image is not upload on user's wall.
so, please tell me how to solve it.
First have you authorized your application to upload pictures by doing this (using the FBConnect SDK), you can checkout all permissions here
NSArray* permissions = [NSArray arrayWithObjects:#"publish_stream", #"user_photos", nil];
[facebook authorize:permissions];
The next problem is that facebook does not allow posts sent in this way to link to pictures hosted on their domains (I know it's REALLY annoying, maybe it would be worth checking if things have changed since april). I spent quite a bit of time working this one out. The way I cracked it was to create a redirect URL using bitly (you can access their services programatically using their API, there's an obj-c wrapper for it here, although I changed it to be asynchronous) and send that URL in the post.
may help u
//facebook post a image on wall
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
userImgView.image, #"picture",
nil];
[facebook requestWithGraphPath:#"me/photos"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
another way is bellow for post image on Facebook ...
NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:2];
//create a UIImage (you could use the picture album or camera too)
UIImage *picture = [UIImage imageNamed:"yourImageName"];
//create a FbGraphFile object insance and set the picture we wish to publish on it
FbGraphFile *graph_file = [[FbGraphFile alloc] initWithImage:picture];
//finally, set the FbGraphFileobject onto our variables dictionary....
[variables setObject:graph_file forKey:#"file"];
[variables setObject:#"write your Message Here" forKey:#"message"];
//the fbGraph object is smart enough to recognize the binary image data inside the FbGraphFile
//object and treat that is such.....
//FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:#"117795728310/photos" withPostVars:variables];
FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:#"me/photos" withPostVars:variables];
hope , this help you...
:)
The facebook API uses OAuth to authenticate requests. You will need to use a library that can request the appropriate temporary/client tokens, and generate the appropriate HTTP headers for requests. This is quite a complicated procedure which involves hashing and normalizing of request arguments.
You cannot do this crafting your own manual HTTP requests .
You can use facebook's native function
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys: UIImageJPEGRepresentation(postImage, 1.0), #"source", self.postTextView.text, #"message", nil];
/* make the API call */
[FBRequestConnection startWithGraphPath:#"/me/photos" parameters:params HTTPMethod:#"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
if (error == nil) {
NSLog("Success");
}
else {
NSLog("Failed");
}
}];
Using this code you can post image with message.
Best regards