I am trying to make a post on another user's wall using another user using FBConnect. I am using the embedded method of the iOS Facebook API (that is, I am forcing the browser to appear inside my app, so I am not leaving the application at all). This method works for posting into the wall of the same user, but doesn't work on the wall of another user.
self.facebook = [[[Facebook alloc] initWithAppId:self.appID andDelegate:self] autorelease];
if ([self.facebook isSessionValid]) {
[self proceedToPost];
}else{
NSArray *permissions = [NSArray arrayWithObjects:#"publish_stream", #"email", #"read_stream", #"manage_pages", nil];
[self.facebook authorize:permissions];
}
- (void)proceedToPost
{
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys: #"aName", #"name",
self.appID, #"app_id",
self.title, #"caption",
self.link, #"link",
#"animateURL", #"picture",
nil];
[params setObject:"my-user-profile-id" forKey:#"to"];
[self.facebook dialog:#"feed" andParams:params andDelegate:self];
}
The problem is that authorization is done as expected, but when trying to actually post, I see an error message in the embedded browser "cannot post to user's wall".
Can anyone help me with this?
Did you request the publish_stream permission from the extended permissions?
From the documentation about publish_stream permission:
Enables your app to post content, comments, and likes to a user's
stream and to the streams of the user's friends. With this permission,
you can publish content to a user's feed at any time, without
requiring offline_access. However, please note that Facebook
recommends a user-initiated sharing model.
http://developers.facebook.com/docs/reference/api/permissions/
You can request permissons like this:
NSArray *permissions = [[NSArray alloc] initWithObjects:
#"publish_stream",
nil];
[facebook authorize:permissions];
[permissions release];
Related
I have tried with openGraph and normal dialog as below,
[facebook requestWithGraphPath:[NSString stringWithFormat:#"/%#/feed",#"friends_fb_id" ] andParams:variables andHttpMethod:#"POST" andDelegate:self];
and
[facebook dialog:#"feed" andParams:params andDelegate:self]
I gave params for both methods as
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"friends_fb_id", #"to",
#"I'm using the Hackbook for iOS app", #"name",
#"Hackbook for iOS.", #"caption",
#"Check out Hackbook for iOS to learn how you can make your iOS apps social using Facebook Platform.", #"description",
#"http://m.facebook.com/apps/hackbookios/", #"link",
#"http://www.facebookmobileweb.com/hackbook/img/facebook_icon_large.png", #"picture",
nil];
in delegate method it correctly return the Post_id, so its completing successfully but I can not see the post on friends wall. If try using the Hackbook app that comes with SDK it works perfectly.
What could be the possible solution.
Did you forget to enable publish_actions or publish_stream permissions during login?
// login to FB
-(void) FBLogin
{
NSArray *permissions = [[NSArray alloc] initWithObjects:#"publish_actions",#"publish_stream", nil];
[FBSession openActiveSessionWithPermissions:permissions allowLoginUI:YES completionHandler:^(FBSession *_session, FBSessionState _status, NSError *_error) {
// do some login handling code here
}];
}
You are using the string "friends_fb_id" should this not be an actual id?
I had a similar situation where is was receiving the correct response, so it was posting, it was just posting to the wrong place.
Make sure the id's are correct.
I'm new to iOS development, I have successfully integrated facebook login and such... however my problem is with the Score api. i can read the score but i cant seem to post it, i have the publish_actions permission and also am getting back a valid access_token.Not sure what the problem it, here is my code -
NSString *accessTokenToUse = [NSString stringWithFormat:#"%#",[self.facebook accessToken] ];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
//#"233", #"score",
accessTokenToUse, #"access_token",
nil];
NSMutableDictionary *paramsB = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"233", #"score",
accessTokenToUse, #"access_token",
nil];
NSLog(#"APP ACCESS TOKEN: %#",accessTokenToUse);
[self.facebook requestWithGraphPath:#"me/scores" andParams:paramsB andHttpMethod:#"POST" andDelegate:self];
[self.facebook requestWithGraphPath:#"APP_ID/scores" andParams:params andHttpMethod:#"GET" andDelegate:self];
***EDIT - Still doesn't work
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"233", #"score",
#"[APP_ACCESS_TOKEN (omitted for stackoverflow)]", #"access_token", nil];
[self.facebook requestWithGraphPath:#"/[userID]/scores" andParams:params andHttpMethod:#"POST" andDelegate:self];
EDIT - SOLVED
So bascially i WAS passing in the correct token, however the facebook sdk was overwriting it in Facebook.m to the user's access token. So the fix was simple - whenever i need to pass in the App's token i just add an other parameter < key=#"useAppToken" Value=#"yes" > and in Facebook.m just add an if statement within isSessionValid -
- (FBRequest*)openUrl:(NSString *)url
params:(NSMutableDictionary *)params
httpMethod:(NSString *)httpMethod
delegate:(id<FBRequestDelegate>)delegate {
NSLog(#"PARAMS BFORE: %# ", params);
[params setValue:#"json" forKey:#"format"];
[params setValue:kSDK forKey:#"sdk"];
[params setValue:kSDKVersion forKey:#"sdk_version"];
if ([self isSessionValid]) {
if ([params objectForKey:#"useAppToken"] == nil || [params objectForKey:#"useAppToken"] == #"no") {
[params setValue:self.accessToken forKey:#"access_token"];
}
}
NSLog(#"PARAMS AFTER: %# ", params);
[self extendAccessTokenIfNeeded];
FBRequest* _request = [FBRequest getRequestWithParams:params
httpMethod:httpMethod
delegate:delegate
requestURL:url];
[_requests addObject:_request];
[_request addObserver:self forKeyPath:requestFinishedKeyPath options:0 context:finishedContext];
[_request connect];
return _request;
}
Be sure to comment out the NSLogs in this... :)
Scores can only be published using application access_token and not one for user (which you probably using, it's ok for reading the scores but don't allow you to publish 'em).
Citing the Scores documentaion:
Create or update a score for a user
You can post a score or a user by issuing an HTTP POST request to /USER_ID/scores with the app access_token as long as you have the publish_actions permission.
Looks like it's a bug:
http://developers.facebook.com/bugs/461900043821056
But if you change your app settings to web app instead of native it would work.
I am using the Facebook IOS library. I am trying to post an image to the user's wall. I am able to upload the image to the application Album, but i can not get it to show up on the user's wall.
The application is granted the publish_stream permissions:
[self.facebook authorize: [NSArray arrayWithObject: #"publish_stream"]];
The image is posted with the following code:
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
UIImagePNGRepresentation(_image), #"source",
message, #"message", nil];
[self.facebook requestWithGraphPath: #"me/photos"
andParams: params
andHttpMethod: #"POST"
andDelegate: self];
This works great - the image end up in the app album on Facebook - now how do I get this image to show up on the user's wall?
Thanks
Greg
I'm trying to post a message to the users wall in out iOS app. The first time the user attempts to do this, the app switches to the Facebook app so they can sign in and accept our app. It then automatically goes back to our app as excepted. It then opens a UIWebView dialog (so the user can post their message to their wall), however an error message is shown in the dialog instead, saying "An error has occurred. Please try again later." Subsequent attempts to post the message work as expected, the issue only seems to occur immediately after signing in or accepting our app on Facebook.
Furthermore, when the error is shown, and the user clicks okay to dismiss the dialog, it then loads the user's wall showing all their friends posts, rather than closing the dialog.
Anybody know any solutions to this issue? I am working off the latest SDK.
Here is the code I use to login and display the dialog.
Authenciating session:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:#"FBAccessTokenKey"]
&& [defaults objectForKey:#"FBExpirationDateKey"]) {
facebook.accessToken = [defaults objectForKey:#"FBAccessTokenKey"];
facebook.expirationDate = [defaults objectForKey:#"FBExpirationDateKey"];
}
if (![facebook isSessionValid]) {
NSArray *permissions = [[NSArray alloc] initWithObjects:
nil];
[facebook authorize:permissions];
[permissions release];
return NO;
}
return YES;
And the code to show the dialog:
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
kAppId, #"app_id",
link, #"link",
imageURL, #"picture",
linkName, #"name",
caption, #"caption",
description, #"description",
nil];
[facebook dialog:#"feed" andParams:params andDelegate:self];
Solved the issue by just making a separate call after it returns back to our app.
I'm trying to use the Facebook iOS "feed" dialog call to allow my app's user to share something on their Facebook wall. When the facebook app is not installed, it attempts to let them authenticate within the app (presumably using a web view). The issue is that this dialog just disappears once they authenticate. I was expecting the web view to return to the "feed" sharing view.
How do I detect that they authenticated so that I can re-open the feed dialog?
I've added fbDidLogin to my app delegate, but it's not being called. (I wasn't sure if this would normally be called or not, but I read several people recommending this.)
SBJSON *jsonWriter = [SBJSON new];
// The action links to be shown with the post in the feed
NSArray* actionLinks = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:
#"More Videos",#"name",#"http://www.example.com/",#"link", nil], nil];
NSString *actionLinksStr = [jsonWriter stringWithObject:actionLinks];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"Test Caption", #"caption",
#"Test Description", #"description",
#"https://s3.amazonaws.com/example/images/test.png",
#"source",
self.video.blogLink, #"link",
#"01234567890123", #"app_id",
actionLinksStr, #"actions",
nil];
[delegate facebook].sessionDelegate = delegate;
[[delegate facebook] dialog:#"feed" andParams:params andDelegate:self];
It turns out the issue is the same as those reporting that the dialog disappears immediately for them. There is a bug in the Facebook SDK in regards to handling error -999, with the solution described in this comment on SO.
I finally realized I was having the same issue (albeit manifesting slightly differently), when I started listening to the FBDialogDelegate's method:
- (void)dialog:(FBDialog*)dialog didFailWithError:(NSError *)error
The error description referenced the -999 error mentioned above, leading me to the answer. Luckily the code checked into github worked flawlessly. I just had to pull it into the SDK codebase and recompile the .a lib file, then include it into my project.
Did you implemented facebook protocol FBSession in your view controller ?
To detect that user is authenticated you have to call isSessionValid:
if (![[self.fbAppDelegate facebook] isSessionValid]) {
NSArray *permissions = [[NSArray alloc] initWithObjects:#"publish_stream",#"create_event",#"offline_access", nil];
[[self.fbAppDelegate facebook] authorize:permissions];
}
and authorize inApp:
[self authorizeWithFBAppAuth:NO safariAuth:NO];