How to post photos to facebook iphone fbconnect - iphone

Hi I'm using FBConnect to post to facebook, now I need to post photos from library or taken with the cam, does anyone has a clue how to do this ?? I've searched in google but I can't find a piece of code that works for me. I've found this method:
FBRequest *uploadPhotoRequest = [FBRequest requestWithDelegate:self];
[uploadPhotoRequest call:#"photos.upload" params:args];
but in my fbconnect i have this one instead: (I think the version of the api is different)
[_fbRequest call:(NSString *) params:(NSDictionary *) dataParam:(NSData *)];
Also I'm using this method to post to the wall:
- (void)postToWall { FBStreamDialog* dialog = [[[FBStreamDialog
alloc] init] autorelease];
dialog.userMessagePrompt = #"Enter your message:";
dialog.attachment = [NSString stringWithFormat:#"{\"name\":\"%# Esta conectado desde TravelFan iPhone App\",\"caption\":\"Viajar te cambia la vida\",\"description\":\"\",\"media\":[{\"type\":\"image\",\"src\":\"http://www.travelfan.com.mx/content/templates/default/images/logo_travel.jpg\",\"href\":\"http://www.travelfan.com.mx/\"}]}",
_facebookName];
dialog.actionLinks = #"[{\"text\":\"Obten TravelFan
App!\",\"href\":\"http://www.travelfan.com.mx/\"}]"; [dialog show];
}
In this method I can send an image but not as a photo its just for the app logo and its an attachment.
Can anyone tell how to post photos to the wall pls ??
Any help is apreciated XD.

You can now post photos on your wall with requestWithGraphPath method as follows.
NSData *yourImageData= UIImagePNGRepresentation(yourImage);
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"Your text with picture", #"message", yourImageData, #"source", nil];
[facebook requestWithGraphPath:#"/me/photos" andParams:params andHttpMethod:#"POST" andDelegate:self];

The requestWithGraphPath method is non-blocking - meaning it will complete before the photo is actually uploaded. You'll know when the photo is finished uploading by implementing the following in your FBRequestDelegate

Related

How to make a friend request with facebook ios sdk?

i'm using the facebook iOS sdk.
I need to send friend requests between users of facebook, from an iOS app.
I know that can not be sent via graph API. I'm trying to through dialog of facebook i do not know how.
Can anyone help me?
This is my code:
Facebook *face = [[Facebook alloc] initWithAppId:#"APP_ID" andDelegate:self];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"user_id", #"id",
nil];
[face dialog:#"me/friends"
andParams:params
andDelegate:self];
With this code i get a dialog with this text: "The page you requested was not found"
Ok I found a solution.
I have created a NSMutableDictionary to make a "appRequest" with their corresponding parameters but finally indicated that the type of dialogue is a "friends".
It's a strange solution but it works.
Facebook *face = [[Facebook alloc] initWithAppId:FBSession.activeSession.appID andDelegate:nil];
face.accessToken = FBSession.activeSession.accessToken;
face.expirationDate = FBSession.activeSession.expirationDate;
if ([face isSessionValid]){
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"My Title", #"title",
#"Come check out my app.", #"message",
userId, #"id",
nil];
[face dialog:#"friends"
andParams:[params mutableCopy]
andDelegate:nil];
}
This may help you
NSDictionary* params = [NSDictionary dictionaryWithObjectsAndKeys: message, #"message", title, #"title", nil];
[[self facebook] dialog: #"apprequests"
andParams: [params mutableCopy]
andDelegate: delegate];
See this question for further details and also this document.

Post image with the old Facebook sdk

I want to post an image from my iPhone app directly to my wall. with out using an image url, with the actual UIImage or NSData.
On the recent FacebookSDK, I can post like:
[FBRequestConnection startWithGraphPath:#"me/photos"
parameters:params ..
and pass NSData of the image in params
but for older version FBConect.h can I have similar option? the one I know so far is by passing the image url as part of the parameters dictionary.
Thanks,
you can post image on your facebook timeline Wall like this way may be its helps you First you need to get permission to post Photo on wall in yourViewDidLoad Method like:-
NSArray* permissions = [NSArray arrayWithObjects:#"publish_stream", #"user_photos", nil];
[facebook authorize:permissions];
now to Post image At your Button Click or your logic like:-
-(IBAction)ActionPostWallPhoto
{
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
ImageView.image, #"picture",
nil];
[facebook requestWithGraphPath:#"me/photos"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
}

How to do wall post on facebook with image stored on iPhone?

I have an application in which i have to post image on Wall of facebook.
Now problem is i used GraphAPI facebook and i have to pass link of photo but i have photo in my iPhone and not on any server.
So how do i post wall with image and other parameters without URL of image?
You may use NSURLConnection ASIHttpRequest library for downloading the images from a url.
You will have to do the following:
1. Create a NSUrlConnection and implement the delegate methods
2. Pass the url in your request and you will get the data in -(void)connectionDidFinishLoading: (NSURLConnection *)connection
3. You can then create a UIImage from this data using UIImage *image = [[UIImage alloc] initWithData:activeDownloadData];
FBStreamDialog *dialog = [[[FBStreamDialog alloc] init] autorelease];
dialog.userMessagePrompt = #"Enter your message:";
NSDictionary *params = nil;
[[FBRequest requestWithDelegate:self] call:#"facebook.photos.upload" params:params dataParam:(NSData*)wallImage];
[dialog show];
Edit:
--
Actually, posting an image to the Facebook wall has to be from the web. So you will have to upload the image first; maybe try a 3rd party service like twitpic or something, return the response url and place it in your params.
--
You can use the following to post with image to Facebook. You can also replace UIImage with a physical URL as well.
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
kAppID, #"app_id",
#"http://bit.ly/dDZQXt", #"link",
#"www.has.to.be.web.based.com", #"picture",
EasyStrings(#"Mobile Profiles for ",device), #"name",
EasyStrings(#"Current Profile: ",currProfile), #"caption",
#"I am using Mobile Profiles for iPhone, iPod touch and iPad.", #"description",
message, #"message",
nil];
[_facebook dialog:#"feed"
andParams:params
andDelegate:self];
What it will look like:
The house icon is loaded from [UIImage imageNamed:#"something.png"].
I modified the facebook demo app. It uses the modal view to select a picture from your phone. You can use this code, granted you must add two buttons (i.e., selectPicture button and a uploadPhoto button) -- also be sure to add to UIViewController in the .h file:
/**
* Upload a photo.
*/
- (IBAction)uploadPhoto:(id)sender {
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
image, #"picture",
nil];
[_facebook requestWithGraphPath:#"me/photos"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
}
/**
* Select a photo.
*/
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
image = [info objectForKey:UIImagePickerControllerOriginalImage];
[self dismissModalViewControllerAnimated:YES];
}
- (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissModalViewControllerAnimated:YES];
}
- (IBAction) selectPicture:(UIButton *)sender;
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
[self presentModalViewController:picker animated:YES];
[picker release];
}
Try using BMSocialShare which is a simple lib I wrote. It is exactly doing what you want. Upload some local image (and even open a dialog for the user to add a comment) to the user's wall:
BMFacebookPost *post = [[BMFacebookPost alloc] initWithImage:[UIImage imageNamed:#"image.png"]];
[[BMSocialShare sharedInstance] facebookPublish:post];

iphone : FBConnect Auto post to user wall

i want to auto post to a user wall from my iphone applications ( without that "publish" "skip" dialog box ). how i can do that ?
the following should be called in the class that implements FBSessionDelegate and FBRequestDelegate:
Facebook *_facebook = [[Facebook alloc] initWithAppId:kAppId];
NSArray *_permissions = [[NSArray arrayWithObjects:
#"read_stream", #"offline_access",nil] retain];
[_facebook authorize:_permissions delegate:self];
And that is the call for fb post (should be used in the same class):
NSString *message = #"This is the message I want to post";
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
message, #"message",
nil];
[_facebook requestWithMethodName:#"stream.publish"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
If you want to post a message on the wall of other user you should include "uid" parameter in your params dictionary. Please consult http://developers.facebook.com/docs/reference/rest/stream.publish/
P.S. There are all the necessary examples in the iPhone Facebook connect SDK sample code, so please do not afraid to investigate just a little bit ;)

FBConnect : send some images on somebody's wall

I found out how to send some text on the user's wall, with the FBConnect API, on iphone.
I even found how to put an image already on the internet :
FBFeedDialog* dialog = [[[FBFeedDialog alloc] init] autorelease];
dialog.delegate = self;
dialog.templateBundleId = 12345;
dialog.templateData = #"{\"image\":[{\"src\":\"http://sample.png\",\"href\":\"http://sample.com\"}] }";
[dialog show];
(see http://wiki.developers.facebook.com/index.php/Facebook_Connect_for_iPhone)
But I can't figure out how to upload an UIImage from my iphone to the user's wall with FB Api.
Do I have, first, to upload the image on any website, then put its url in the templateData ?
Isn't there any simpler solution ?
Thanks.
Martin
Use the below function to upload the image, pass the UIImage as the parameter, it will work.
- (void)uploadPhoto:(UIImage *)uploadImage
{
NSMutableDictionary *args = [[[NSMutableDictionary alloc] init] autorelease];
[args setObject:uploadImage forKey:#"image"]; // 'images' is an array of 'UIImage' objects
[args setObject:#"4865751097970555873" forKey:#"aid"];// this should be album id
uploadPhotoRequest = [FBRequest requestWithDelegate:self];
[uploadPhotoRequest call:#"photos.upload" params:args];
NSLog(#"uploading image is successful");
}
[[FBRequest requestWithDelegate:self] call:#"facebook.photos.upload" params:params dataParam:(NSData*)img;
and pass params to nil . it will upload image to default album