How to Post an Image to facebook wall? - iphone

Using this Tutorail i scceessfully login to Facebook
http://www.raywenderlich.com/1626/how-to-post-to-a-users-wall-upload-photos-and-add-a-like-button-from-your-iphone-app
But i have NO Experience with facebook for iOS .
- (IBAction)rateTapped:(id)sender {
NSURL *url = [NSURL URLWithString:#"YOur Image url"];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[UIImage alloc] initWithData:data];
[variables setObject:img forKey:#"picture"];
FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:#"/me/photos"
withPostVars:variables];
}
But here i confused that how we can pass image url ,bcz my image is on the same page And also when i use this code its gives me following four Errrors.
I have no luck. What's wrong? Thanks in advance

Please see this post - How to share or post by mail, twitter and facebook from the current application?
In this you will found How to share an UIImage to Facebook, Twitter, and Email.

1st error is due to an *undeclared variable.*
You are not added Facebook sdk to your project, that's why you are getting 2,3 & 4th errors.
For using Facebook features in your application you need to integrate Facebook API to your project.
The latest face book API is known as Graph API.
For further reference visit http://developers.facebook.com/docs/reference/api/
How to integrate Facebook sdk to your project:
http://www.raywenderlich.com/77/how-to-post-on-facebook-with-your-iphone-app

Related

Is it possible to bypass the share dialog and post directly to Facebook? in share kit

i Successfully bypass the Twite dialog and post directly to Twitter In ShareKit using following Code
SHKTwitter *twitter = [SHKTwitter new];
[twitter authorize];
SHKItem *item = [SHKItem new];
[item setCustomValue:#"i am tweeting" forKey:#"status"];
twitter.item = item;
[twitter send];
item.shareType = SHKShareTypeText;
item.text = #"hi";
But now also want to apply it to Facebook. plz help me
i use above code from here
Thanks In Advance
FBGraph is much better way to use facebook API in your app.
download the FBGraph Api documents folder then add it to in your folder.
and read the instruction on facebook developer site http://developers.facebook.com/docs/reference/api/.
this is the sample code - sample code
and let me know if you have any query about it.
No it's possible to imitate the Share dialog directly.
You can use the /ID/feed connection but the user status update will appear as "via your app".

iPhone : Posting an image to facebook's wall with comment message using oAuth support

Posting an image to facebook's wall with comment message using oAuth support from the latest sdk provided by facebook.
Please provide useful links.
Follow the instructions here to integrate the latest Facebook SDK and get a valid session: Facebook SDK for iOS Getting Started
There is a sample app included with the SDK to get you started as well.
Then in your code, do something like this, where "session" is declared
Facebook * session;
- (void) sendFacebookMessage:(NSString *) messageText withCaption:(NSString *) captionText) andImage:(UIImage *) image {
NSMutableDictionary *args = [[[NSMutableDictionary alloc] init] autorelease];
[args setObject:captionText forKey:#"caption"];
[args setObject:messageText forKey:#"message"];
[args setObject:UIImageJPEGRepresentation(image, 0.7) forKey:#"picture"];
[session requestWithMethodName:#"photos.upload" andParams:args ndHttpMethod:#"POST" andDelegate:self];
}

Facebook iOS Integration

I have recently implemented the Facebook functionality to post an URL as explained in iOS Facebook Development
It's the same as explained.
After I've signed up on Facebook and set my app key, I started the iPhone simulator and authorized as explained on Facebook. After that the Mobile Safari didn't jump back to my app (Because I don't want Facebook to jump back. Later I want to do that calling a webpage by my own). So I just started it again (activated because of iOS 4.2).
After that, I switched to the where I post a default URL.
NSMutableDictionary *params = [NSMutableDictionary dictionary];
NSString *communityURL = #"http%3A%2F%2Fwww.google.com";
[params setObject:communityURL forKey:#"link"];
[facebook dialog:#"feed" andParams:params andDelegate:self];
Normally it should bring up a dialog with this parameters, but it just showed an error:
This page contains the following errors:
error on line 25 at column 35: xmlParseEntityRef: no name
Below is a rendering of the page up to the first error.
When I debug into the method which calls the dialog, I got the URL, which will be called.
When executing this URL in a web browser, it works.
Why doesn't it work?
What's wrong?
i didn't figure out what it was, but i came up with an other solution.
I now use ShareKit. It's easy to use and it handles all alone. I try to post some sourcecode snipets asap.
For those, who have the same problem and don't want to use another API, try to do what ever the facebook documentation tells you.
Br
Nic
ok what I did is simply add
NSURL *url = [NSURL URLWithString: #"http://www.google.com"];
SHKItem *item = [SHKItem URL:url title:#"Share Item with Google url ;)"];
// Get the ShareKit action sheet
SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
// Display the action sheet
[actionSheet showFromTabBar:self.tabBarController.tabBar];
And that's what I do.
If someone needs help, please feel free!!
Br
Nic

How to use FBConnect dialog method to post a UIImage to my wall?

(Note: I've looked all over for this, and there are tons of examples for how to post a URL-to-image via dialog, and a few for how to post image-data direct to photo album, but neither of those are what I'm trying to do.)
I can post an image that's stored on the web easily enough with code similar to this:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"This is what I say about kittens!", #"message",
#"Kittens!", #"name",
#"I'm feeling fuzzy", #"caption",
#"You, too, can feel fuzzy, with FuzzyKittenâ„¢", #"description",
#"http://example.com/fuzzykitten.html", #"link",
#"http://placekitten.com/200/150", #"picture",
nil];
[facebook dialog: #"feed"
andParams: params
andDelegate: self];
And everything works fine. The problem is, I'd like to replace:
#"http://placekitten.com/200/150", #"picture",
with something along the lines of:
[UIImage imageNamed: #"myImage.png"], #"picture",
which, of course, isn't right. So my question is: If I have an image in UIImage form, how do I load that into the parameters dictionary to pass to the dialog method?
Thanks!
EDIT: This is a client iPhone app for which there is no server so, while uploading the image to FB as part-1 of a 2-part process is fine, I'm now not seeing how to find the uploaded image's URL. Thanks again!
You can't directly upload an image to the wall, when publishing to the wall you can just link an image to it.
So, you need to upload the UIImage somewhere first. You have 2 options:
1. Upload to your/some server and publish a wall post linking to it.
2. Upload to a facebook album. Check the graph API about doing that, it is pretty straightforward.
edit: you can no longer source images hosted in facebook CDN (and probably other CDNs), so if you need to link an image from a dialog you should upload it on a server and get a permalink from there
You could use ASIFormDataRequest and run a script to upload your file to your server using something like this:
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
// Upload a file on disk
[request setFile:#"/Users/ben/Desktop/ben.jpg" withFileName:#"myphoto.jpg" andContentType:#"image/jpeg"
forKey:#"photo"];
Then have the ASIFormDataRequest's response return the url of the uploaded image to your application.
You can use the event of the ASIFormDataRequest response to trigger the Facebook image post.

How to upload video on facebook using iphone sdk 4.0 or above?

I have to upload video on facebook using iphone sdk 4.0 or above.
Here is the code I am using:
FBRequest m_UploadRequest = [[FBRequest requestWithSession: _session delegate: self] retain];
NSURL *videoUrl=[NSURL URLWithString:#"clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"];
NSData VideoFileData = [NSData dataWithContentsOfURL:videoUrl];
NSMutableDictionary* Parameters = [NSMutableDictionary dictionaryWithObjectsAndKeys: #"video.upload", #"method", #"Video Title", #"title", nil];
[m_UploadRequest call: #"facebook.video.upload" params:Parameters dataParam: VideoFileData]; //not working...
Thanks in advance
Pankaj
in my case if am using this code then
[FBRequest requestWithSession:delegate:]: unrecognized selector sent to class 0x4b910
also check the related questions
Uplooad Video facebook-ios-sdk : uploaded but not shown on my FB Wall and in My Video
Facebook iOS Upload Video "Unable to retrieve session key from the access token."
Step 1. Learn how to upload a video for the iPhone. Hint: Look into NSURLConnection and NSOperation. If you are really motivated take a look at ASIHTTPRequest.
Step 2. Learn how to use the Facebook API. Good luck here, their docs are terrible.
Step 3. Put your newfound knowledge to work and wire it all up together. Profit!