I am trying to post to friend wall and it wouldn't work. I can post to my wall though.
- (void)publishStory
{
NSString *graph=#"me/feed";
if([self.friendId length]!=0){
graph=[NSString stringWithFormat:#"%#/feed", self.friendId];
}
self.postParams = [#{
#"link" : self.link,
#"picture" : self.imageUrl,
#"name" :self.name,
#"caption" :self.caption,
#"description" : self.postMessageTextView.text
} mutableCopy];
[FBRequestConnection
startWithGraphPath:graph
parameters:self.postParams
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
NSString *alertText;
if (error) {
NSLog(#"Error publish %#", error.localizedDescription);
alertText = [NSString stringWithFormat:
#"error: domain = %#, code = %d",
error.domain, error.code];
} else {
alertText = #"Posted to Facebook. Thank you";
}
// Show the result in an alert
[[[UIAlertView alloc] initWithTitle:#"Result"
message:alertText
delegate:self
cancelButtonTitle:#"OK!"
otherButtonTitles:nil]
show];
}];
}
This is the error.
body = {
error = {
code = 200;
message = "(#200) The user hasn't authorized the application to perform this action";
type = OAuthException;
};
};
code = 403;
Related
I need to publish Open Graph story to Facebook wall from my app. I followed current tutorial on Facebook developers.
I've created object,action and story on Facebook dashboard. Then in my app do the following code:
create an object:
NSMutableDictionary<FBOpenGraphObject> *object = [FBGraphObject openGraphObjectForPost];
object.provisionedForPost = YES;
object[#"title"] = #"test title";
object[#"type"] = #"myapp:my_object_type";
object[#"description"] = #"test discription";
object[#"url"] = #"http://example.com";
object[#"image"] = #[#{#"url": [result objectForKey:#"uri"], #"user_generated" : #"false" }];
and post it:
[FBRequestConnection startForPostOpenGraphObject:object completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(!error) {
NSString *objectId = [result objectForKey:#"id"];
NSLog(#"object id %#",objectId);
} else {
NSLog(#"Error posting the Open Graph object to the Object API: %#", error);
}
}];
} else {
NSLog(#"Error staging an image: %#", error);
}
}];
Got object id as result.
Then create an action and link it with object:
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
[action setObject:objectId forKey:#"my_object_type"];
FBOpenGraphActionParams *params = [[FBOpenGraphActionParams alloc] init];
params.action = action;
params.actionType = #"myapp:my_app_action";
And post it to Facebook:
[FBRequestConnection startForPostWithGraphPath:#"/me/myapp:my_app_action" graphObject:action completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(!error) {
NSLog(#"OG story posted, story id: %#", [result objectForKey:#"id"]);
[[[UIAlertView alloc] initWithTitle:#"OG story posted"
message:#"Check your Facebook profile or activity log to see the story."
delegate:self
cancelButtonTitle:#"OK!"
otherButtonTitles:nil] show];
} else {
NSLog(#"Encountered an error posting to Open Graph: %#", error);
}
}];
As a result i got the message that OG story was successfully posted, but when going to Facebook, there is nothing in feed or timeline, just an image added to users photo album.
Well, dunno what was the problem, but now it works with the following code:
FBRequestConnection *connection = [[FBRequestConnection alloc]init];
NSMutableDictionary <FBOpenGraphObject> *object = [FBGraphObject openGraphObjectForPost];
object[#"type"] = #"myapp:my_object_type";
object[#"title"] = #"title";
object[#"url"] = #"http://example.com";
object[#"image"] = #"http://image.png";
object[#"description"] = #"description";
FBRequest *objectRequest = [FBRequest requestForPostOpenGraphObject:object];
[connection addRequest:objectRequest completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (error) {
NSLog(#"Error: %#",error.description);
}
} batchEntryName:#"objectCreate"];
NSMutableDictionary <FBOpenGraphAction> *action = [FBGraphObject openGraphActionForPost];
action[#"buy"] = #"{result=objectCreate:$.id}";
action[#"fb:explicitly_shared"] = #"true";
FBRequest *actionRequest = [FBRequest requestForPostWithGraphPath:#"me/myapp:my_app_action" graphObject:action];
[connection addRequest:actionRequest completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (error) {
NSLog(#"error: %#",error.description);
} else {
NSLog(#"posted with id %#", result[#"id"]);
}
}];
[connection start];
In my App, I've created Facebook Integration when I click on Facebook login it goes to Safari browser, how can change it to dialogue box login without entering via Safari web browser?
Thanks In Advance.
[FBSession.activeSession closeAndClearTokenInformation];
if (FBSession.activeSession.accessTokenData.loginType != FBSessionLoginTypeFacebookApplication /||
FBSession.activeSession.accessTokenData.loginType !=
FBSessionLoginTypeSystemAccount/) {
[HUD hide:YES];
HUD = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
HUD.labelText = #"Signing In";
[FBSession openActiveSessionWithReadPermissions:#[#"basic_info",#"email",#"user_location",#"user_birthday",#"user_hometown,user_friends"]
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
switch (state) {
case FBSessionStateOpen:{
[FBSession setActiveSession:session];
[self checkSessionState:state];
[[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection
*connection, NSDictionary *user, NSError *error) {
if (error) {
[HUD hide:YES];
NSLog(#"error Report :%#",error);
}
else
{
[HUD hide:YES];
NSString *userLocation = [NSString stringWithFormat:#"%#\n\n",user.location[#"name"]];
NSArray* foo = [userLocation componentsSeparatedByString: #","];
NSString *strCity = [foo objectAtIndex: 0];
NSString *strState = [foo objectAtIndex: 1];
NSString *linkURL = [NSString stringWithFormat:#"http://carzillaapp.com/"];
NSString *pictureURL = #"http://www.friendsmash.com/images/logo_large.jpg";
// NSString *pictureURL = #" ";
// Prepare the native share dialog parameters
FBShareDialogParams *shareParams = [[FBShareDialogParams alloc] init];
shareParams.link = [NSURL URLWithString:linkURL];
shareParams.name = #"Download and Checkout CarZilla App!";
shareParams.caption= #"An online Car Showroom!";
shareParams.picture= [NSURL URLWithString:pictureURL];
shareParams.description =
[NSString stringWithFormat:#"Both new and old cars available there!"];
if ([FBDialogs canPresentShareDialogWithParams:shareParams]){
[FBDialogs presentShareDialogWithParams:shareParams
clientState:nil
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
NSLog(#"Error publishing story.");
} else if (results[#"completionGesture"] &&
[results[#"completionGesture"] isEqualToString:#"cancel"]) {
NSLog(#"User canceled story publishing.");
} else {
NSLog(#"Story published.");
}
}];
} else {
// Prepare the web dialog parameters
NSDictionary *params = #{
#"name" : shareParams.name,
#"caption" : shareParams.caption,
#"description" : shareParams.description,
#"picture" : pictureURL,
#"link" : linkURL
};
// 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.");
}
}}];
}
NSDictionary *params = #{
#"name" : shareParams.name,
#"caption" : shareParams.caption,
#"description" : shareParams.description,
#"picture" : pictureURL,
#"link" : linkURL
};
[FBWebDialogs presentRequestsDialogModallyWithSession:nil
message:[NSString stringWithFormat:#"Checkout the CarZilla App!"]
title:#"Invite"
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error)
{
if (error) {
// Case A: Error launching the dialog or sending request.
NSLog(#"Error sending request.");
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
// Case B: User clicked the "x" icon
NSLog(#"User canceled request.");
} else {
NSLog(#"Request Sent.");
}
}}
];
SignUpViewController *faceblogin = [[SignUpViewController alloc]init];
faceblogin.firstName = [NSString stringWithFormat:#"%# ",user.first_name];
faceblogin.lastName = user.last_name;
faceblogin.email =[user objectForKey:#"email"];
faceblogin.city = strCity;
faceblogin.state = strState;
faceblogin.fblogin = YES;
fbFailure = YES;
fbMsg = YES;
faceblogin.accountType = #"Individual Buyer/Seller";
//faceblogin.isPhoneno = YES;
[self presentViewController:faceblogin animated:YES completion:nil];
}
}];
break;
}
case FBSessionStateClosed:{
[HUD hide:YES];
NSLog(#"facebook values");
}
case FBSessionStateClosedLoginFailed:{
[HUD hide:YES];
if ((!fbFailure && fbMsg) || error.code == 2) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"Error" message:#"Unfortunately, we
were not able to log you in using your Facebook credentials."
delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
fbMsg = NO;
[alert show];
}
[FBSession.activeSession closeAndClearTokenInformation];
break;
}
default:
break;
}
} ];
}
else{
NSLog(#"accounts"); }
I used following code to invite a friend to my app:
NSString *facebookID = user.id;
NSMutableDictionary* params =
[NSMutableDictionary dictionaryWithObject:facebookID forKey:#"to"];
NSString *message = #"SOME_MESSAGE";
NSString *title = #"TITLE";
FBSession *facebookSession = [PFFacebookUtils session]; //You may changed this if you are not using parse.com
[FBWebDialogs presentRequestsDialogModallyWithSession:facebookSession
message:message
title:title
parameters:params handler:
^(FBWebDialogResult result, NSURL *resultURL, NSError *error)
{
if (!error) {
NSLog(#"Succees:%#",resultURL);
}
}]; }
Opens WebDialog as shown:
But I see no invitation on my profile. How do I get it done properly?
str_id = [[app.Arr_Facebook_Frnd objectAtIndex:indexpath] objectForKey:#"id"];
str_name = [[app.Arr_Facebook_Frnd objectAtIndex:indexpath] objectForKey:#"name"];
str_link = #"www.google.com";
NSDictionary *params = #{
#"name" : str_name,
#"caption" : #"",
#"description" : #"",
#"picture" : #"",
#"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];
}
}}];
[self.indicator stopAnimating];
you didn't mention if the console printed "Success...." or not.
anyway, if the request is successfull users will see it only on fb mobile app
Iam using the following code to post a message on my friend's facebook wall. This code posts message to the logged in users wall but not to the friend's wall
Iam also giving the "to" value and i.e., friends facebook id (116623456) and App_id but same problem persists.
Please provide a good direction on this.
- (void)facebookViewControllerDoneWasPressed:(id)sender
{
NSLog(#"DonePressed Called");
NSString* fid;
NSString* fbUserName;
NSString *message = [NSString stringWithFormat:#"You have been selected as a health coach(Multiple Users1), You will be receiving daily and weekly reports from here on!!!!"];
NSLog(#"Before For");
// NSString *SelectedFriends = nil;
for (id<FBGraphUser> user in _friendPickerController.selection)
{
fid = user.id;
fbUserName = user.name;
NSLog(#"User Name =%#, USer id =%#",fbUserName, fid);
}
NSLog(#"After For");
NSLog(#"%#",fid);
NSMutableDictionary *params =
[NSMutableDictionary dictionaryWithObjectsAndKeys:
#"4444444444444444",#"app_id",
fid,#"to",
nil];
// Invoke the dialog
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:params
handler:
^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
// Error launching the dialog or publishing a story.
NSLog(#"Error publishing story.");
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
// User clicked the "x" icon
NSLog(#"User canceled story publishing.");
} else {
// Handle the publish feed callback
NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
if (![urlParams valueForKey:#"post_id"]) {
// User clicked the Cancel button
NSLog(#"User canceled story publishing.");
} else {
// User clicked the Share button
// Show the result in an alert
[[[UIAlertView alloc] initWithTitle:#"Result"
message:#"Message Posted Successfully"
delegate:self
cancelButtonTitle:#"OK!"
otherButtonTitles:nil]
show];
}
}
}
}];
}
- (void)facebookViewControllerDoneWasPressed:(id)sender {
NSMutableString *text = [[NSMutableString alloc] init];
// we pick up the users from the selection, and create a string that we use to update the text view
// at the bottom of the display; note that self.selection is a property inherited from our base class
for (id<FBGraphUser> user in self.friendPickerController.selection) {
if ([text length]) {
[text appendString:#", "];
}
[text appendString:user.name];
NSString *fid=user.id;
NSString *fbUserName=user.name;
NSLog(#"");
NSMutableDictionary* params = [[NSMutableDictionary alloc] initWithObjectsAndKeys:#"Test miLineup!", #"message", #"Iphone Apps", #"name", nil];
NSLog(#"\nparams=%#\n", params);
//Post to friend's wall.
[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:#"%#/feed", fid] parameters:params HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
//Tell the user that it worked.
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Shared"
message:[NSString stringWithFormat:#"Invited %#! error=%#", fbUserName, error]
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
];
//Close the friend picker.
//[self dismissModalViewControllerAnimated:YES];
}
I'm creating iOS app using latest Facebook framework 3.1
I've seen lots of content regarding posting image and text to facebook user's wall. I'm using the following code.
NSDictionary* dict = #{
#"link" : #"https://developers.facebook.com/ios",
#"picture" : [UIImage imageNamed:#"Default"],
#"message":#"Your temp message here",
#"name" : #"MyApp",
#"caption" : #"TestPost",
#"description" : #"Integrating Facebook in ios"
};
[FBRequestConnection startWithGraphPath:#"me/feed" parameters:dict HTTPMethod:#"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSString *alertText;
if (error)
{
NSLog(#"%#",[NSString stringWithFormat: #"error: domain = %#, code = %d", error.domain, error.code]);
alertText = #"Failed to post to Facebook, try again";
} else
{
alertText = #"Posted successfully to Facebook";
}
[[[UIAlertView alloc] initWithTitle:#"Facebook Result" message:alertText delegate:nil cancelButtonTitle:#"OK!" otherButtonTitles:nil] show];
}];
If I'm providing the picture as "URL" its posting fine. Else its throwing error. I want to post an image that is within the application bundle. Can some on tell me where I'm coding wrong?
UIImage* image = [UIImage imageNamed:#"nature.jpg"];
NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
[params setObject:#"My First message" forKey:#"message"];
[params setObject:image forKey:#"picture"];
[FBRequestConnection startWithGraphPath:#"me/photos" parameters:dict HTTPMethod:#"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSString *alertText;
if (error)
{
NSLog(#"%#",[NSString stringWithFormat: #"error: domain = %#, code = %d", error.domain, error.code]);
alertText = #"Failed to post to Facebook, try again";
} else
{
alertText = #"Posted successfully to Facebook";
}
[[[UIAlertView alloc] initWithTitle:#"Facebook Result" message:alertText delegate:nil cancelButtonTitle:#"OK!" otherButtonTitles:nil] show];
}];