Facebook SDK 4.0: Asking publish
I am using FBSDKLoginButton for logging in through Facebook in my App. Well I define the readPermissions as;
NSArray *permissions = [NSArray arrayWithObjects:@"public_profile", @"email",nil];
self.loginFbBtn.readPermissions = permissions;
The above goes all well. But now if I need to ask permissions for a post to my timeline and want to have access to " publish_actions " permissions, is there a way to ask these without actually provoking FBSDKLoginManager , because that is the only way given in Facebook docs:
if ([[FBSDKAccessToken currentAccessToken] hasGranted:@"publish_actions"]) {
// TODO: publish content.
} else {
FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
[loginManager logInWithPublishPermissions:@[@"publish_actions"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
//TODO: process error or result.
}];
}
Apparently this is the only way you can invoke " publish_actions " for your app. I want to use it without the FBSDKLoginManager . Please help, I need to get this rolling.
SO THIS IS THE UPDATE:
By the help of Wizkid and MingLi I ended up implementing it via FBSDKLoginManager and the following code segments are for Facebook Login via a custom button and its @selector(facebookLogin)
, and then sharing permissions invoked when sharing is required via method getSharingPermissions
:
-(void) facebookLogin
{
@try
{
self.loginManager = [[FBSDKLoginManager alloc] init];
[self.loginManager setLoginBehavior:FBSDKLoginBehaviorWeb];
[self.loginManager logInWithReadPermissions:@[@"public_profile",@"email"] handler:^(FBSDKLoginManagerLoginResult *result,NSError *error)
{
if([FBSDKAccessToken currentAccessToken])
{
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error)
{
if (!error)
{
NSLog(@"fetched user:%@", result);
NSDictionary *userDict = (NSDictionary*)result;
}
}];
}}];
}
}
@catch (NSException *exception)
{
NSLog(@"Exception %@", exception);
}
Get Sharing Permissions:
-(void)getSharePermissions
{
if (![[FBSDKAccessToken currentAccessToken] hasGranted:@"publish_actions"])
{
[self.loginManager setLoginBehavior:FBSDKLoginBehaviorWeb];
[self.loginManager logInWithPublishPermissions:@[@"publish_actions"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
{
if ([result.grantedPermissions containsObject:@"publish_actions"])
{
}}];
}
}
So the error is I am getting the Login page again and is asking User Credentials again when getSharingPermissions
is called. Please help. Thanks in advance.