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.
Related
I'm building an iPad app where the user can post an image to his/her timeline.
These iPads are rentable, so the user should be logged out after the share has been done.
I've implemented the iOS Facebook Login, so the user is redirected to Safari to login. After the share I clean up all the tokens and within my app the session is destroyed, but when I go to Safari afterwards the user is still logged in.
Is there a way to make sure the user is logged out everywhere?
Kind regards,
Frederik
I've done something similar in the past.
It was a flow where any user holding the iPad logs in with his or hers FB credentials, forcing the sdk to present a webview.
A quick look, this is the code I wrote for it:
(this code is 1.5y old)
FBSession *newSession = [[FBSession alloc] initWithPermissions:#[
#"user_about_me",
#"publish_actions",
#"user_birthday",
#"friends_birthday",
#"email"
]];
[FBSession setActiveSession:newSession];
[[FBSession activeSession] openWithBehavior:FBSessionLoginBehaviorForcingWebView completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
[FBSession setActiveSession:session];
if(error){
NSLog(#"Error opening session");
[self showLoginError:error];
return;
}
if(status == FBSessionStateOpen){
NSLog(#"FB session opened");
[self getMe];
}
}];
When the flow ends, or the user cancels the flow, I logs the user out as follows:
[[FBSession activeSession] closeAndClearTokenInformation];
[FBSession setActiveSession:nil];
UPDATE:
The code for the share dialog:
NSMutableDictionary *dialogParameters = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSString stringWithFormat:#"%# - Vote for us!",
teamName, #"name",
#"Campaign title", #"caption",
shareMessage, #"description",
shareTeamPageURL, #"link",
sharePictureURL, #"picture", nil];
[FBWebDialogs presentFeedDialogModallyWithSession:[FBSession activeSession]
parameters:dialogParameters
handler:nil];
I'm trying to find solution for my problem during two days. And I want to say what I'm sure what I've read all resource where you could give me a links =)
The problem is. I'm using FacebookSDK 3.1 for iOS. And trying to make apprequests dialog... The code is simple
session =[[FBSession alloc]initWithAppID:#"XXXXXXXXXXXX" permissions:nil urlSchemeSuffix:#"xxxxxxxxxxxx" tokenCacheStrategy:nil];
[FBSession setActiveSession:session];
[self ShowSessionState:session.state];
NSLog(#"Acces token data: %#",[session accessToken]);
[session openWithCompletionHandler:^(FBSession *psession, FBSessionState status, NSError *error) {
// NSLog(#"I'm in");
Facebook * facebook = [[Facebook alloc] initWithAppId:#"XXXXXXXXXXXX" urlSchemeSuffix:#"xxxxxxxxx" andDelegate:nil];
[facebook setAccessToken:FBSession.activeSession.accessToken];
[facebook setExpirationDate:FBSession.activeSession.expirationDate];
[facebook dialog:#"apprequests" andDelegate:nil];
}];
And all what I see.. just Frame with error - Api Error Code:110; Api Error Description: invalid user Id; Error message: Missing user cookie (to validate session user).
But the authorization is successful... I have a valid accessToken.. can get my friends or my own FB data.
As I said I've read a lot of resources.... And really the many people have same problem, but I don't found any useful solution for this problem. So help me, please.
I'm found a solution, maybe it will help somebody else. Actually it looks like exorcism but works) So the problem is: If you logged in facebook from safary or Facebook app, webview doesn't save any cookie... so you need make you logging from webview. You can do it with FBConnect package (read more in google). In Facebook.m file you need change code like this:
[self authorizeWithFBAppAuth:YES safariAuth:YES];
to
[self authorizeWithFBAppAuth:NO safariAuth:NO];
In that case when you will use
[facebook authorize:permissions];
The login come always in webview and you can use any dialogs like apprequests etc.
The one more problem)) Login Dialog doesn't appear? It's one more Facebook bug)) To solve this you just need make a delay when call it:
[self performSelector:#selector(showFBLoginDialog) withObject:nil afterDelay:1];
- (void)showFBLoginDialog {
NSArray *permissions = [[NSArray alloc] initWithObjects:
#"offline_access",
#"publish_actions",
#"read_stream",
#"user_photos",
#"email",
#"publish_stream",
#"user_likes",
#"user_about_me", nil];
[facebook authorize:permissions];
}
I am trying to post on a Facebook friend's wall, I tried these two methods but none work:
1.
//post on wall
NSMutableDictionary *variables = [[NSMutableDictionary alloc]initWithCapacity:1];
[variables setObject:#"v" forKey:#"message"];
[graphref doGraphPost:[NSString stringWithFormat:#"1389799421/feed"] withPostVars:variables];
//post on wall
2.
[_facebook requestWithGraphPath:#"1389799421/feed"
andParams:[NSMutableDictionary dictionaryWithObject:#"test wall post" forKey:#"message"]
andHttpMethod:#"POST"
andDelegate:self];
...and I can't understand why!! On the facebook website I have added the bundle and the permissions.
I am trying to post on a Facebook friend's wall
Facebook recently announced in the developer blog, that posting to another user’s wall through the API will not be possible any more from Feb 2013 on:
Removing ability to post to friends walls via Graph API
We will remove the ability to post to a user's friends' walls via the Graph API. Specifically, posts against [user_id]/feed where [user_id] is different from the session user, or stream.publish calls where the target_id user is different from the session user, will fail. If you want to allow people to post to their friends' timelines, invoke the feed dialog.
So I think it’s pretty useless starting to develop a feature like that now.
First off, you have to open your session with publish permissions. Specifically, you must request the publish_stream permission.
NSArray * permissions = [[NSArray alloc] initWithObjects:#"publish_stream", nil];
return [FBSession openActiveSessionWithPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceFriends allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
[self sessionStateChanged:session
state:status
error:error];
}];
If you have publish permissions, you can create and send the request. Make sure you include the access_token as one of the parameters. If you don't, you will get authentication errors.
NSDictionary * postParameters = [NSDictionary dictionaryWithObjectsAndKeys:_textView.text, #"message", FBSession.activeSession.accessToken, #"access_token", nil];
NSString * graphPath = #"ID_NUMBER_HERE/feed";
FBRequest * request = [FBRequest requestWithGraphPath:graphPath parameters:postParameters HTTPMethod:#"POST"];
[[request initWithSession:FBSession.activeSession graphPath:graphPath parameters:postParameters HTTPMethod:#"POST"] startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSLog(#"Successful posted to Facebook");
}];
}
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];
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];