0

我在脸书上做了这个

[self vSuspendAndHaltThisThreadTillUnsuspendedWhileDoing:^{
    [[NSOperationQueue mainQueue] addOperationWithBlock:^{
        [self.ACAstore requestAccessToAccountsWithType:self.ACAccounts options:[self dicPostOptions] completion:^(BOOL granted, NSError *error) {
            self.bPermissionToAccessStoreGranted=granted;
            [self vContinue];
        }];
    }];
}];

基本上我要求发布许可。我要做的是在再次询问之前检查是否已授予此类发布权限。

怎么做?

4

3 回答 3

0

检查可用权限:

      if(![postRequest.session.permissions containsObject:@"publish_actions"])
于 2013-08-26T10:10:58.453 回答
0

您可以FBRequest使用开放图形 API 与me/permissions. 它将返回一个带有字典的响应,其中键是权限。

FBRequest *req = [FBRequest requestWithGraphPath:@"me/permissions" parameters:Nil HTTPMethod:@"GET"];
[req startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary* result,
NSError *error) {
      BOOL canPublish = FALSE;
      if (!error)
      {
         FBGraphObject *data = [result objectForKey:@"data"];
         for(NSDictionary<FBGraphObject> *aKey in data) 
         {
             canPublish = [[aKey objectForKey:@"publish_stream"] boolValue];
         }
      }
      else
      {
         NSLog(@"%@", error);
      }

      NSLog(@"%@", canPublish ? @"I have publish perms" : @"I don't have publish perms");
}];
于 2013-08-26T10:25:03.233 回答
0

尝试这个 -

首先在您的应用程序委托中实现所有 facebook sdk 委托方法。

- (IBAction)loginWithFacebookButtonTapped:(id)sender
{
    IntubeAppDelegate *delegat = (IntubeAppDelegate*)[[UIApplication sharedApplication] delegate];
    [delegat doLoginAndSwitch];
}

现在,在你的 appDelegate -

-(void) doLoginAndSwitch
{      
    [self openSessionWithAllowLoginUI:YES];
}

- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI
{
    NSArray *permissions = [NSArray arrayWithObjects:@"email", nil]; 
    return [FBSession openActiveSessionWithPublishPermissions:permissions
                                      defaultAudience:FBSessionDefaultAudienceFriends
                                         allowLoginUI:YES
                                    completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {

                                        [self sessionStateChanged:session
                                                            state:state
                                                            error:error];

                                    }];
}

-(BOOL)openSessionWithAllowPublishStreamPermission:(BOOL)allowLoginUI
{
    NSArray *permissions = [NSArray arrayWithObjects:@"publish_actions",@"publish_stream", nil];

[[FBSession activeSession] requestNewPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceEveryone completionHandler:^(FBSession *session, NSError *error){
}];
    return YES;
}

- (void)sessionStateChanged:(FBSession *)session
              state:(FBSessionState)state
              error:(NSError *)error
{
    switch (state) {
        case FBSessionStateOpen:
            if(!error)
            {
                //  NSLog(@"FBSessionStateOpen :- logged in");

                [self openSessionWithAllowPublishStreamPermission:YES];

               // Your code
            }
     }    
} 

我希望你现在能得到你想要的。:)

于 2013-08-27T09:43:55.050 回答