i am new in ios , i want to write something on my friend post . i am try this code using graph
api this is not working please help me
NSMutableDictionary* params = [NSMutableDictionary dictionary];
[params setObject:#"Some text" forKey:#"user_message_prompt"];
[params setObject:#"another text" forKey:#"action_links"];
[params setObject:#"Yet another text" forKey:#"attachment"];
[params setObject:#"SOME FACEBOOK ID" forKey:#"target_id"];
FBRequest *request = [[FBRequest alloc] initWithSession:FBSession.activeSession
graphPath:#"https://graph.facebook.com/100000329153640/feed"
parameters:params
HTTPMethod:#"POST"];
NSLog(#"%#",request);
in this NSlog-- request line return this
graphPath: https://graph.facebook.com/100000329153640/feed, HTTPMethod: POST, parameters: {
"action_links" = "another text";
attachment = "Yet another text";
"migration_bundle" = "fbsdk:20131212";
"target_id" = "SOME FACEBOOK ID";
"user_message_prompt" = "Some text";
}>
please give me solution
please share your valuable knowledge ... i am waiting
Thankyou
Try this one,
NSMutableDictionary *params = [NSMutableDictionary new];
[params setObject:#"Some text" forKey:#"user_message_prompt"];
[params setObject:#"another text" forKey:#"action_links"];
[params setObject:#"Yet another text" forKey:#"attachment"];
[params setObject:#"SOME FACEBOOK ID" forKey:#"target_id"];
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
NSLog(#" RESULT : %u",result);
}
];
Refer Developer Guide for facebook
Facebook Developer guide
The first thing you need to do is request publish permissions. I wrote this helper method to do it:
void runBlockWithPublishPermissions(void (^block)(FBSession *))
{
FBSession *session = [FBSession activeSession];
NSString *publishPermission = #"publish_actions";
// If we already have publish permissions, then submit.
if (([session isOpen] && FB_ISSESSIONOPENWITHSTATE(session.state)) &&
[session.permissions containsObject:publishPermission])
{
block(session);
}
// Else request for the permissions, then submit.
else
{
[session requestNewPublishPermissions:#[publishPermission]
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
if (!error)
{
block(session);
}
else
{
NSLog(#"Failed to request publish permissions: %#", error);
}
}];
}
}
You would then use your code in the following way:
void (^submit)(FBSession *) = ^(FBSession *session){
NSMutableDictionary* params = [NSMutableDictionary dictionary];
[params setObject:#"Some text" forKey:#"user_message_prompt"];
[params setObject:#"another text" forKey:#"action_links"];
[params setObject:#"Yet another text" forKey:#"attachment"];
[params setObject:#"SOME FACEBOOK ID" forKey:#"target_id"];
FBRequest *request = [[FBRequest alloc] initWithSession:session
graphPath:#"https://graph.facebook.com/100000329153640/feed"
parameters:params
HTTPMethod:#"POST"];
[request startWithCompletionHandler:nil];
};
runBlockWithPublishPermissions(submit);
Related
I am using the following code to upload an image from my iOS to Facebook.
NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
[params setObject:#"MY TEST MSG..." forKey:#"message"];
[params setObject:UIImagePNGRepresentation(self.editImageView.image) forKey:#"picture"];
[[FBSDKGraphRequest alloc] initWithGraphPath:#"me/photos" parameters:params HTTPMethod:#"POST"] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSLog(#"uploaded");
} else {
NSLog(#"Graph API Error: %#", [error description]);
}
}];
My app got stuck for couple of minutes and show the error message.
Can any one please help me?
NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:3];
UIImage *picture = FilterImage;
FbGraphFile *graph_file = [[FbGraphFile alloc] initWithImage:picture];
[variables setObject:graph_file forKey:#"file"];
[variables setObject:[NSString stringWithFormat:#"Hello testin"] forKey:#"message"];
[fbGraph doGraphPost:#"me/photos" withPostVars:variables];
NSLog(#"Now log into Facebook and look at your profile & photo albums...");
I'm trying to share a post with this code:
// Put together the dialog parameters
NSMutableDictionary *params = [[NSMutableDictionary alloc]init];
[params setValue:[Campaign sharedInstance].name forKey:#"name" ];
[params setValue:#"desription" forKey:#"description"];
[params setValue:picture.facebookPicture.link forKey:#"link"];
[params setValue:picture.facebookPicture.source forKey:#"picture"];
// Show the feed dialog
[FBWebDialogs presentFeedDialogModallyWithSession:nil parameters:params handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if(error) {
[basicViewController toastMessage:[#"Error sharing on Facebook: " stringByAppendingString:error.localizedDescription]];
}}];
I'm getting an error because the source of the picture is from facebook.
What can i do to add the wanted facebook picture and still using the fbwebdialogs?
In Facebook, you can post something and share it with just some friends.
How can this be done programmatically on iOS using Facebook SDK?
My App has an "Emergency Button" that sends: a) User Location on a Map (picture); b) An emergency text (message); and c) The post is only shared with the friends the user has chosen in the config. section (privacy).
- (void)sendMessage {
//Just an Example: Send an Emergency Post with: message, picture, just to SOME friends.
//This action may not need the User to actually press a button.
//Privacy parameter obtained from:
//https://developers.facebook.com/docs/graph-api/reference/v2.0/post/
NSMutableDictionary *privacy = [[NSMutableDictionary alloc]initWithObjectsAndKeys:
#"100000278095294,100000278095528", #"allow", //Friends Id separeted with commas.
#"", #"deny",
#"CUSTOM", #"value", //Privacy Custom Value
nil];
NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
[params setObject:self.emergencyText forKey:#"message"];
[params setObject:self.locationMap forKey:#"picture"];
[params setObject:privacy forKey:#"privacy"];
[FBRequestConnection startWithGraphPath:#"me/feed"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
if (error) {
NSLog(#"Error");
NSLog(#"Error descriptcion %#",error.description);
}else{
NSLog(#"Success");
}
}];
}
This code in not running. I get an error from Facebook.
If I comment this line:
// [params setObject:privacy forKey:#"privacy"];
Then it runs fine and I see the post in FB, but it is a public post.
I need to post: message, picture, just to some friends.
Any solution using startWithGraphPath or using any other command is welcome!
You must format the privacy as a JSON string and then assign that json string to the params NSMutableDictionary.
For Example:
NSMutableDictionary *privacy = [[NSMutableDictionary alloc]initWithObjectsAndKeys:
#"100000278095294,100000278095528", #"allow", //Friends Id separeted with commas.
#"", #"deny",
#"CUSTOM", #"value", //Privacy Custom Value
nil];
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:privacy
options:NSJSONWritingPrettyPrinted
error:&error];
NSString *jsonString;
if (! jsonData) {
NSLog(#"Got an error: %#", error2);
} else {
jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}
NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
[params setObject:#"to my friend" forKey:#"message"];
[params setObject:self.locationMap forKey:#"picture"];
[params setObject:jsonString forKey:#"privacy"];
I'm trying to post a message on a friends wall using requestWithGraphPath:parameters:HTTPMethod: method but its not working.
Here is my code,
-(void)shareAdOnFacebook
{
NSMutableDictionary *params = [NSMutableDictionary dictionary];
[params setObject:#"Test post with silent authentication" forKey:#"message"];
[params setObject:#"link" forKey:#"type"];
[params setObject:#"http://yoursite.com" forKey:#"link"];
[params setObject:#"Link description" forKey:#"description"];
NSString *graphPath = #"[user_id]/feed";
[FBRequest requestWithGraphPath:graphPath parameters:params HTTPMethod:#"POST"];
}
There is no error but it doesn't post anything. I'm trying to get it to work on iOS5 and above.
Any advice?
NSArray *permissions =[NSArray arrayWithObjects:#"publish_actions",#"publish_stream",#"manage_friendlists", nil];
[[FBSession activeSession] reauthorizeWithPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
/* handle success + failure in block */
}];
Source from:Referance
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/