Upload image to form in webview, without displaying image picker - iphone

I am trying to fill up a web form and submit data without letting the user see the web form itself. I have tried using AFNetworking to do HTTP POST in the background, but I bumped into a problem which I couldn't solve and decided to try something else.
This time, I have a UIWebView which is hidden in the background. I then edit the text in the respective fields using Javascript in the webViewDidFinishLoad:webView as follows:
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
[params setObject:nameField.text forKey:#"name"];
[params setObject:emailField.text forKey:#"email"];
[params setObject:titleField.text forKey:#"title"];
[params setObject:dateString forKey:#"link"];
[params setObject:descriptionTV.text forKey:#"content"];
[params setObject:tag forKey:#"tags"];
[params enumerateKeysAndObjectsUsingBlock:^(id key, id object, BOOL *stop) {
NSLog(#"%# = %#", key, object);
NSString *javascriptString = [NSString stringWithFormat:#"document.getElementById('%#').value = '%#'",key,object];
[webView stringByEvaluatingJavaScriptFromString:javascriptString];
}];
Is there any way I could do the same, but for uploading images/files?

You should use an NSHTTPRequest to POST the image to the form directly. There is no need to use a UIWebView, hidden or otherwise. See this answer for an example of how to implement this. Here is another example of this.

Related

iOS: Posting a photo to Facebook and small html as caption

Is it possible to upload an image to photo album and include a small html code as caption with it?
I would like to use the new Graph API to do this.
The following code works, but when I set my text variable to an html code, the caption appears as plain text with all the html tags visible.
Also, in the following code, the its.title is completely ignored when item.text is not null.
if (item.shareType == SHKShareTypeImage && item.image)
{
if (item.title)
NSLog(#"title = %#", item.title);
[params setObject:item.title forKey:#"caption"];
if (item.text) {
NSString *mytext = [NSString stringWithFormat:#"%#\n\nCreated by iPhone app FaceMod: %#", item.text,appURL];
[params setObject:mytext forKey:#"message"];
}
[params setObject:item.image forKey:#"picture"];
// There does not appear to be a way to add the photo
// via the dialog option:
[[SHKFacebook facebook] requestWithGraphPath:#"me/photos"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
[self retain]; //must retain, because FBConnect does not retain its delegates. Released in callback.
return YES;
}
My understanding is that the way to post html is to using the "action" key:
NSString *actions = [NSString stringWithFormat:#"{\"name\":\"%# %#\",\"link\":\"%#\"}",
SHKLocalizedString(#"Get"), SHKCONFIG(appName), SHKCONFIG(appURL)];
[params setObject:actions forKey:#"actions"];
But this does not work either and the "action" html code is ignored and does not appear of Facebook.
Thanks for the help.
No. You can't inject HTML into the caption field: Facebook doesn't let you set HTML for values that are displayed in multiple places. Any HTML you submit will be treated as plain text to prevent any HTML injection attacks or visual style changes.

Share image on facebook using FBConnect

After searching 2 days on it m finally posting my code.
Application Description: I am choosing an image through imagePicker and after editing it I want to share it on Facebook.
Problem: I can post the text on my wall but not the image, as i dont have any URL i cant find another way to post image on my wall.
here is the code ( which i stole from another application) of my PostToWall
FBStreamDialog* dialog = [[[FBStreamDialog alloc] init] autorelease];
dialog.userMessagePrompt = #"Enter your message:";
dialog.actionLinks = #"[{\"Get DowntownLA!\",\"href\":\"http://www.facebook.com/DowntownLA.com/\"}]";
dialog.attachment = [NSString stringWithFormat:
#"{ \"name\":\"%#\","
"\"href\":\"%#\","
"\"caption\":\"%#\",\"description\":\"%#\","
"\"media\":[{\"type\":\"image\","
"\"src\":\"%#\","
"\"href\":\"%#\"}],"
"\"properties\":{\"%#\":{\"text\":\"%#\",\"href\":\"%#\"}}}", #"name: priya",#"href nothing",#"cation nothing",#"description nothin", #"imageSource nothing ", #"imageHref nothing", #"linkTitle nothing", #"linkText nothing", #"linkHref nothing"];
[dialog show];
Please tel me wher m going wrong !!!!!
The error m getting on simulator is : Application Response Error - The post action links must be valid URls. You can see this because you are one of the developers of the app.
i have upload image in this way
- (void) postOnFBWall
{
NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:2];
//create a UIImage (you could use the picture album or camera too)
UIImage *picture = imgUploadPhoto.image;
//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"];
NSString * messageValue = [NSString stringWithFormat:#"Menu Name: %#, Restaurant: %#, Category: %#, Comment: %#",txtNameofMenu.text,txtRestaurant.text,categoryLbl.text,txtViewComment.text];
[variables setObject:[NSString stringWithFormat:#"%#",messageValue] 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 = [[FBRequestWrapper defaultManager] doGraphPost:#"me/photos" withPostVars:variables];
NSLog(#"postPictureButtonPressed: %#", fb_graph_response.htmlResponse);
}

Facebook video Upload error

Facebook video upload error: i'm using the combination of the old
and the new API/SDK from the link https://github.com/zoul/facebook-ios-sdk/commit/efb4b44fad333f8daa70a517bb5328b9352320df
and i m getting session id properly in the video Upload class
- (void) startUploadWithURL: (NSURL*) movieURL params: (NSDictionary*) userParams delegate: (id ) delegate
{
apiKey = #"5c009deec3b253bef6fe6cdd97e86b3f";
appSecret = #"218421681dfb46043bed3dd25a03bbce";
if ([self sessionID] == nil) {
NSLog(#"Unable to retrieve session key from the access token.");
return;
}
printf(" \n\n session id == %s",[[self sessionID] UTF8String]);
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:userParams];
[params setObject:#"1.0" forKey:#"v"];
[params setObject:#"facebook.video.upload" forKey:#"method"];
[params setObject:[self sessionID] forKey:#"session_key"];
[params setObject:apiKey forKey:#"api_key"];
[params setObject:[self signatureForParams:params] forKey:#"sig"];
[params setObject:[NSData dataWithContentsOfURL:movieURL] forKey:[movieURL lastPathComponent]];
[[FBRequest getRequestWithParams:params httpMethod:#"POST" delegate:delegate requestURL:kAPIURL] connect];
}
its returning the wrong result and not uploading video to the Facebook
Without using graph api you can upload videos to facebook.login facebook and go to this link. there you will get a id like xyz#m.facebook.com .just mail your videos to this mail id.you can use a MFmailcompossor to compose mail from your app.
Hope this help

Facebook graph api with native iPhone application

I want to use the Facebook Graph API in a NATIVE iPhone Application. Has anybody been able to find a way to post images/message on a user's feed?
I have tried all possible ways to post a ‘picture’ (not a URL but a UIImage) on the feed and have been working on this for 2 weeks now.
If you go to facebook.com you can upload a picture from your computer on to the wall. I am using ASIHTTPRequest to work on facebook graph API.
This is the nearest I have gone to posting a picture on the feed. So if I have a ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
The url is https://graph.facebook.com/me/feed
Now to post a picture I do the following:
[request setPostValue:#"My Message" forKey:#"message"];
[request setPostValue:#"somepic.png" forKey:#"picture"];
[request setPostValue:#"Some Name" forKey:#"name"];
[request setPostValue:#"Some description" forKey:#"description];
[request startAsynchronous];
If you try this then everything works fine other than the picture being posted. A blank placeholder for the picture is though show on the feed.
I created a method to help me do this. Hope this is of some help.
Please read the tutorial on how to set up the Facebook SDK.
-(void) updateStatusWithText:(NSString *) fbTitle //Status title
andStoryURL:(NSString *) fbURL //URL for the story
andStory:(NSString *) fbStory //The story
andImage:(NSString *) imageURL //Image to be displayed.
andPrompt:(NSString *) promptString{
NSLog(#"updateStatusWithText");
NSString *attachmentText =[NSString stringWithFormat:#"{\"name\":\"%#\","
"\"href\":\"%#\","
"\"description\":\"%#\","
"\"media\":[{\"type\":\"image\","
"\"src\":\"%#\","
"\"href\":\"%#\"}],"
"\"properties\":{\"Uploaded from an iPhone\":{\"text\":\"AFL Fan\",\"href\":\"Your itunes apstore URL\"}}}", fbTitle, fbURL, fbStory,imageURL,fbURL];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
promptString, #"user_message_prompt",
// actionLinksStr, #"properties",
attachmentText, #"attachment",
nil];
NSLog (#"attachmentText : %#", attachmentText);
[facebook dialog:#"stream.publish"
andParams:params
andDelegate:self];
}

FBConnect (IPHONE) , custom publish dialog

is possible custominzing the FBdialog??, i have already modify the attachment on the dialog when the user wants to publish a post; but i need to make hidden the textfield that the dialog presents...there is a way to access to this property or it's just a webView that load a page from facebook's server?
sorry for my bad english!
thanks in advance
Yes, this is possible. just design your own UI and pass the message to a method containing this code:
NSString *message = #"test message here";
NSMutableDictionary *params = [NSMutableDictionary dictionary];
[params setObject:message forKey:#"message"];
[params setObject:toID forKey:#"target_id"];
[[FBRequest requestWithDelegate:self] call:#"facebook.Stream.publish" params:params];