FBConnect : send some images on somebody's wall - iphone

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

Related

iPhone:Error occurs while uploading image on twitter using sharekit

I am using sharekit to upload the image on twitter.
I have set keys and callback URL perfectly.
But after entering my login and password credentials
to upload image on twitter I got following error message.
"There was a problem requesting access from Twitter."
Earlier before few months in the same app I was able to upload
the image with same code.
But right now I am facing the problem
can you tell me what is the exact problem
thanks in advance.
There is some changes occur in share kit. To resolve this issue. You have to change some piece of lines in SHKTwitter.mfile under this method:
- (void)tokenAccessModifyRequest:(OAMutableURLRequest *)oRequest
For detail info follow this link & make changes according to this link & then check:
https://github.com/SteveLeviathan/ShareKit/commit/7aab77655c1cbb1bf79092fcb3bb24dd80ab6380
UPDATE:
Replace your this method with my & then check:
- (void)tokenAccessModifyRequest:(OAMutableURLRequest *)oRequest
{
if (xAuth)
{
NSDictionary *formValues = [pendingForm formValues];
OARequestParameter *username = [[[OARequestParameter alloc] initWithName:#"x_auth_username"
value:[formValues objectForKey:#"username"]] autorelease];
OARequestParameter *password = [[[OARequestParameter alloc] initWithName:#"x_auth_password"
value:[formValues objectForKey:#"password"]] autorelease];
OARequestParameter *mode = [[[OARequestParameter alloc] initWithName:#"x_auth_mode"
value:#"client_auth"] autorelease];
[oRequest setParameters:[NSArray arrayWithObjects:username, password, mode, nil]];
}
else {
if (self.pendingAction == SHKPendingRefreshToken)
{
if (accessToken.sessionHandle != nil)
[oRequest setOAuthParameterName:#"oauth_session_handle" withValue:accessToken.sessionHandle];
}
else
[oRequest setOAuthParameterName:#"oauth_verifier" withValue:[authorizeResponseQueryVars objectForKey:#"oauth_verifier"]];
}
}
You can switch to ShareKit 2 - it is being updated frequently.

How to post photos to facebook iphone fbconnect

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

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

Publish to Facebook wall from iPhone application

No Matter what i do, i cannot get a post published to an application page wall (the app being logged into) via an iPhone application. I'm able to log in using FBLoginDialog and then retrieve data to populate a tableview, however when i click a button to publish some test content it doesn't work. Here is the button action:
- (void)compose:(id)sender;
{
NSString *tid=#"115372005166292";
NSString *body = #"My Test";
NSArray *obj = [NSArray arrayWithObjects:body,[NSString stringWithFormat:#"%#", tid],nil];
NSArray *keys = [NSArray arrayWithObjects:#"message",#"target_id",nil];
NSDictionary *params = [NSDictionary dictionaryWithObjects:obj forKeys:keys];
[[FBRequest requestWithDelegate:self] call:#"facebook.stream.publish" params:params];
}
I have also used the FBStreamDialog which works, however i'm faced with two issues there. The dialog lacks customization and i'm unable to handle the callback when the item is posted (e.g. reload the tableview)
I've been searching the internet and all of the examples are similar to the code above, so i'm not sure what i could be missing.
Thanks
You need to ask for extended permissions. After login show this:
FBPermissionDialog* dialog = [[[FBPermissionDialog alloc] init] autorelease];
dialog.delegate = self;
dialog.permission = #"status_update";
[dialog show];
Doc: http://github.com/facebook/facebook-iphone-sdk/#readme

Post message on facebook wall from iPhone

I want to post some message on Facebook wall.
I am able to log in and connect with Facebook from iPhone. But I have hard luck to finding out the solution.
Can you please tell me how I can achieve this functionality?
Assuming that you have a valid FBSession Object:
FBStreamDialog* dialog = [[[FBStreamDialog alloc] init] autorelease];
dialog.delegate = self; dialog.userMessagePrompt = #"Example prompt";
dialog.attachment = #"{\"name\":\"Facebook Connect for iPhone\"," "\"href
\":\"http://developers.facebook.com/connect.php?tab=iphone\"," "\"caption\":\"Caption
\",\"description\":\"Description\"," "\"media\":[{\"type\":\"image\"," "\"src
\":\"http://img40.yfrog.com/img40/5914/iphoneconnectbtn.jpg\"," "\"href
\":\"http://developers.facebook.com/connect.php?tab=iphone/\"}]," "\"properties \":{\"another link\":{\"text\":\"Facebook home page\",\"href\":\"http://www.facebook.com\"}}}"; // replace this with a friend's UID // dialog.targetId = #"999999";
[dialog show];
Source: Facebook Connect Reference