请求到端点的错误' me / feed':必须为对此端点的调用指定打开的FBSession

时间:2015-05-14 04:26:00

标签: ios8.1 facebook-share

我知道这个问题多次发布,但我确实没有得到任何可以解决我问题的建议。我在这个问题上浪费了两天时间,但直到现在我还没有得到任何解决方案。请提供宝贵的指导。

我想在Facebook上发布状态。

  if ([PostType isEqual:@"article"])
    {

        [dict setObject:PostTitle forKey:@"message"];
        params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                  PostTitle, @"message", nil];

        if (FBSession.activeSession.isOpen) {

            // Yes, we are open, so lets make a request for user details so we can get the user name.
            if ([[[FBSession activeSession] permissions]indexOfObject:@"publish_actions"] == NSNotFound) {

                [[FBSession activeSession] requestNewPublishPermissions:[NSArray arrayWithObjects: @"publish_actions",nil] defaultAudience:FBSessionDefaultAudienceFriends
                                                      completionHandler:^(FBSession *session,NSError *error){
                                                          [self promptUserWithAccountName];
                                                      }];

            }else{
                [self promptUserWithAccountName];
            }

            // a custom method - see below:



        } else {


            NSArray *permissions = [[NSArray alloc] initWithObjects:
                                    @"publish_actions",
                                    nil];

            // OPEN Session!
            [FBSession openActiveSessionWithPermissions:permissions
                                           allowLoginUI:YES
                                      completionHandler:^(FBSession *session,
                                                          FBSessionState status,
                                                          NSError *error) {
                                          // if login fails for any reason, we alert
                                          if (error) {

                                              // show error to user.

                                          } else if (FB_ISSESSIONOPENWITHSTATE(status)) {

                                              // no error, so we proceed with requesting user details of current facebook session.

                                              [self promptUserWithAccountName];   // a custom method - see below:
                                          }

                                      }];  
        }

自定义方法:

 -(void)promptUserWithAccountName {
[[FBRequest requestForMe] startWithCompletionHandler:
 ^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
     if (!error) {

         [FBRequestConnection startWithGraphPath:@"me/feed"
                                      parameters:params
                                      HTTPMethod:@"POST"
                               completionHandler:^(FBRequestConnection *connection,
                                                   id result,
                                                   NSError *error){

                                   if (!error) {
                                       UIAlertView *tmp = [[UIAlertView alloc]
                                                           initWithTitle:@"Success"
                                                           message:@"Photo Uploaded"
                                                           delegate:self
                                                           cancelButtonTitle:nil
                                                           otherButtonTitles:@"Ok", nil];

                                       [tmp show];

                                   } else {
                                       UIAlertView *tmp = [[UIAlertView alloc]
                                                           initWithTitle:@"Error"
                                                           message:@"Some error happened"
                                                           delegate:self
                                                           cancelButtonTitle:nil
                                                           otherButtonTitles:@"Ok", nil];

                                       [tmp show];

                                   }


                               }];



     }



 }];

 }

0 个答案:

没有答案