I have followed this link to post on friends wall but its not posting actually instead it just lists the no of friends and allows for multiple selection of friends, there is no option for posting on friends wall.
Not getting satisfactory answer please help me how to post on friends wall using FBWebDialogs, as other ways using Graph api to post on users wall is disabled by facebook.
Any help would be much appreciated. Thanks.
Finally I got the answer of my own question, how easier it was !! but it took my couple of days reaching out there.
To post on your friends wall first of all you need is a permission publish_actions.
And here is the simple code :
NSMutableDictionary *params = [NSMutableDictionary new];
[params setObject:#"YOUR DESC" forKey:#"description"];
[params setObject:#"YOUR LINK" forKey:#"link"];
[params setObject:#"YOUR CAPTION" forKey:#"caption"];
[params setObject:#"FRIEND_ID" forKey:#"to"];
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
NSLog(#" RESULT : %u",result);
}
];
Make sure you have added Facebook SDK in you bundle
and have imported necessary class.
That's it..
Look on this,
NSDictionary *params = #{#"name" :#"Your name",
#"caption" : #"",
#"description" :#"Your description"],
#"picture" : #"Your Image link",
#"link" : #"Your link",
};
// Invoke the dialog
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:params
handler:
^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
NSLog(#"Error publishing story.");
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
NSLog(#"User canceled story publishing.");
} else {
NSLog(#"Story published.");
}
}}];
Related
In my application, I need to use Feed Dialog for the cases when Facebook App is not installed in users phone.
Even though I can share content with FBDialogs canPresentShareDialogWithParams method, I can't get Feed Dialog work. Dialog isn't opening and handler is not getting called.
[FBWebDialogs presentFeedDialogModallyWithSession:nil parameters:params handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
NSLog(#"Error publishing story: %#", error.description);
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
NSLog(#"User cancelled.");
} else {
NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
if (![urlParams valueForKey:#"post_id"]) {
NSLog(#"User cancelled.");
} else {
NSString *result = [NSString stringWithFormat: #"Posted story, id: %#", [urlParams valueForKey:#"post_id"]];
// do stuff
NSLog(#"result %#", result);
}
}
}
}];
Teste on iOS7 and iOS8 and the result it's always the same.
What worked for me is to change both the picture and link fields from type NSURL to NSString. In the Facebook docs there is a good example of how to do it:
NSMutableDictionary *params =
[NSMutableDictionary dictionaryWithObjectsAndKeys:
#"Facebook SDK for iOS", #"name",
#"Build great social apps and get more installs.", #"caption",
#"The Facebook SDK for iOS makes it easier and faster to develop Facebook integrated iOS apps.", #"description",
#"https://developers.facebook.com/ios", #"link",
#"https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png", #"picture",
nil];
I believe this would fix your problem.
Hi i am using following code to post to friends wall which is working fine.
i want to prefill that text in text view where it says write something on friend's wall.
is it possible to edit it ? if yes then how ?
here is the code
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"Sharing Tutorial", #"name",
#"Build great social apps and get more installs.", #"caption",
#"Allow your users to share stories on Facebook from your app using the iOS SDK.", #"description",
#"https://developers.facebook.com/docs/ios/share/", #"link",
#"http://i.imgur.com/g3Qc1HN.png", #"picture",
#"100006771363037",#"to",
nil];
// Show the feed dialog
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(#"Error publishing story: %#", error.description);
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
// User canceled.
NSLog(#"User cancelled.");
} else {
// Handle the publish feed callback
NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
if (![urlParams valueForKey:#"post_id"]) {
// User canceled.
NSLog(#"User cancelled.");
} else {
// User clicked the Share button
NSLog(#"fb web dialog result=====>%#",result);
NSString *result = [NSString stringWithFormat: #"Posted story, id: %#", [urlParams valueForKey:#"post_id"]];
NSLog(#"result %#", result);
}
}
}
}];
thats definitely possible:
set the text of your textview to the desired pre filled text:
textView.text = #"Allow your users to share stories on Facebook from your app using the iOS SDK.";
and use the textViews's text for the dictionary you are sending to Facebook, maybe via some self defined method like
- (void)postToFacebookWithCaption:(NSString*)caption text:(NSString*)text{
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"Sharing Tutorial", #"name",
caption, #"caption",
text, #"description",
#"https://developers.facebook.com/docs/ios/share/", #"link",
#"http://i.imgur.com/g3Qc1HN.png", #"picture",
#"100006771363037",#"to",
nil];
//insert code to show the feed dialog
}
I am using facebook SDK 3.13 for posting on user's friends wall using fbwebdialogs. When i set params for this dialog it does not show them on dialog.
NSMutableDictionary *params=[NSMutableDictionary new];
FBSession *ses=[FBSession activeSession];
[params setValue:#"hello" forKey:#"caption"];
[params setValue:#"hello" forKey:#"decription"];
[params setValue:#"whats" forKey:#"name"];
[params setValue:#"http://i.imgur.com/g3Qc1HN.png" forKey:#"picture"];
[params setValue:#"http://www.dsvv.org" forKey:#"link"];
[FBWebDialogs presentFeedDialogModallyWithSession:ses parameters:params handler:^(FBWebDialogResult result,NSURL *url,NSError *error){
if (error) {
}
}];
}
it does not identify these link and produce an error. If someone who posted on user's friends wall please notify me regarding this.
str_link = #"www.google.com";
NSString *str_img = [NSString stringWithFormat:#"%#uploads/%#-5.jpg",app.Main_url,[Data_Dict objectForKey:#"deal_id"]];
//NSLog(#"%#",str_img);
NSDictionary *params = #{
#"name" : str_name,
#"caption" : #"",
#"description" : #"",
#"picture" : str_img,
#"link" : str_link,
#"to":str_id,
};
// Invoke the dialog
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:params
handler:
^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
NSLog(#"Error publishing story.");
[self.indicator stopAnimating];
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
NSLog(#"User canceled story publishing.");
[self.indicator stopAnimating];
} else {
NSLog(#"Story published.");
[self.indicator stopAnimating];
}
}}];
I am posting an image to facebook through FBRequestConnection.
How can I post a map to FB by giving a latitude and longitude. (Also attaching some text with this)
Please advise.
if (FBSession.activeSession.isOpen) {
NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
[params setObject:#"Posting from padivattom" forKey:#"message"];
[params setObject:UIImagePNGRepresentation(image) forKey:#"picture"];
[FBRequestConnection startWithGraphPath:#"me/photos"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
{
if (error)
{
//showing an alert for failure
}
else
{
//showing an alert for success
}
}];
I used the method:
[FBWebDialogs presentFeedDialogModallyWithSession:
parameters:
handler:
to post message and map to facebook. (Its post to news feed).
But you can try to add to your dictionary: [params setObject:[NSString stringWithFormat:#"https://maps.google.com/?q=%#,%#",latitude,longitude] forKey:#"link"];
(If it doesn't work, you can find the Feed Dialog sample on facebook developers page).
I hope it helps
I am using the following code to upload an image to Facebook wall :
UIImage *img = [UIImage imageNamed:#"logoits.png"];
[FBRequestConnection startForUploadPhoto:img
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSLog(#"Facebook posting %#",result);
NSLog(#"Facebook posting %#",error);
}];
It works as expected but I would like to add a message or title to this uploaded photo, and looking at the documentation of FBRequestConnection there is no example of that. http://developers.facebook.com/docs/sdk-reference/iossdk/3.0/class/FBRequestConnection/
How do I upload an image with message?
In the Facebook SDK 3.0 only a image can be post using the given methods, and for other actions you need to use graph a pi's.
So for post a image with message you need to use graph-api. Here is the line of codes which lets you to post a image with message on users timeline.
NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
[params setObject:#"your custom message" forKey:#"message"];
[params setObject:UIImagePNGRepresentation(_image) forKey:#"picture"];
_shareToFbBtn.enabled = NO; //for not allowing multiple hits
[FBRequestConnection startWithGraphPath:#"me/photos"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
{
if (error)
{
//showing an alert for failure
[self alertWithTitle:#"Facebook" message:#"Unable to share the photo please try later."];
}
else
{
//showing an alert for success
[UIUtils alertWithTitle:#"Facebook" message:#"Shared the photo successfully"];
}
_shareToFbBtn.enabled = YES;
}];
and also make sure _shareToFbBtn is enabled only after login is success.
linesvishy's solution works great and it's also worth to note that if you were using Facebook SDK 3.1 and you used method
FBRequest *request = [FBRequest requestForUploadPhoto:_imageToShare];
You can just use the following lines to replace it:
NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
[params setObject:_textToShare forKey:#"message"];
[params setObject:_imageToShare forKey:#"picture"];
FBRequest *request = [FBRequest requestWithGraphPath:#"me/photos" parameters:params HTTPMethod:#"POST"];
Hope it helps! Happy Coding!
Here is an example that posts and image and a note:
http://developers.facebook.com/docs/tutorials/ios-sdk-tutorial/publish-open-graph-story/