-1

我正在开发一个 iPhone 应用程序,在这个应用程序中,我可以选择与 Facebook 分享我的帖子(我只是传递 facebook 用户的用户 ID,而我的服务器端开发人员负责发布部分)我可以获取用户 ID虽然登录脸书但问题是 - 在用户从 facebook 进行身份验证后,“代表您发布”没有进入应用程序(我正在使用 ios6 SDK)(我已经在 facebook 中创建了我的应用程序并检查了来自图表的 public_action ) 我已经浏览了 facebook 开发者页面中给出的教程(美味),但无法做到

这是我的代码-如果有人发现错误或缺少的部分,请帮我清除

AppDelegate.h

#import <FacebookSDK/FacebookSDK.h>

@class ViewController;

@interface AppDelegate : UIResponder

@property (strong, nonatomic) FBSession *session;
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) ViewController *viewController;
@property (strong,nonatomic) IBOutlet UINavigationController *navBar;
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI;
@end

AppDelegate.m

#import "AppDelegate.h"
#import "ViewController.h"
#define APP_ID @"fd725FDE45a44198a5b8ad3f7a0ffa09"


@implementation AppDelegate
@synthesize session = _session;



- (BOOL)application:(UIApplication *)application
        openURL:(NSURL *)url
 sourceApplication:(NSString *)sourceApplication
     annotation:(id)annotation {


     return [self.session handleOpenURL:url];


 }



 - (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {

   NSArray *permissions = [[NSArray alloc] initWithObjects:
                        @"user_location",
                        @"user_birthday",
                        @"user_likes",
                        @"email",
                        @"publish_action",
                        nil];
   return [FBSession openActiveSessionWithPermissions:permissions
                                      allowLoginUI:allowLoginUI
                                 completionHandler:^(FBSession *session,
                                                     FBSessionState state,
                                                     NSError *error) {
                                     [self sessionStateChanged:session
                                                         state:state error:error];
                                 }];


      }

     - (void)sessionStateChanged:(FBSession *)session
                  state:(FBSessionState)state
                  error:(NSError *)error
     {

    switch (state) {
        case FBSessionStateOpen: {
             FBCacheDescriptor *cacheDescriptor = [FBFriendPickerViewController    cacheDescriptor];
        [cacheDescriptor prefetchAndCacheForSession:session];
       }
        break;
        case FBSessionStateClosed: {
                    [FBSession.activeSession closeAndClearTokenInformation];

        [self performSelector:@selector(showLoginView)
                   withObject:nil
                   afterDelay:0.5f];
       }
        break;
        case FBSessionStateClosedLoginFailed: {
                    [self performSelector:@selector(showLoginView)
                   withObject:nil
                   afterDelay:0.5f];
        }
        break;
        default:
        break;
        }


        }



   @end

邀请朋友ViewController.h

    @interface InviteFriendViewController : 
    -(IBAction)fbfrnds:(id)sender;
    - (void)updateView;
    @end

邀请朋友视图控制器.m

  - (void)viewDidLoad
  {
   [super viewDidLoad];
    [self.navigationController setNavigationBarHidden:YES];
     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

     userid = [defaults objectForKey:@"userid"];

      AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];

     if (!appDelegate.session.isOpen) {
      appDelegate.session = [[FBSession alloc] init];


       if (appDelegate.session.state == FBSessionStateCreatedTokenLoaded) {
        [appDelegate.session openWithCompletionHandler:^(FBSession *session,
                                                         FBSessionState status,
                                                         NSError *error) {
            [self updateView];
        }
         ];
         }
         }
         }




     -(void)facebookReteriveInformation:(NSDictionary *)dictnry{



       FriendlistViewController *friends = [[FriendlistViewController      alloc]initWithNibName:@"FriendlistViewController" bundle:nil];

           friends.token = string;

      [self.navigationController pushViewController:friends animated:YES];


       }



     -(IBAction)fbfrnds:(id)sender{



     sharedClass=[SharedClass sharedInstance];

     appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;


      AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];

     if (appDelegate.session.isOpen) {

       [self updateView];
        } else {
    if (appDelegate.session.state != FBSessionStateCreated) {
        appDelegate.session = [[FBSession alloc] init];
    }

    [appDelegate.session openWithCompletionHandler:^(FBSession *session,
                                                     FBSessionState status,
                                                     NSError *error) {
        [self updateView];
     }];
      }

    NSLog(@"string issss %@",string);


       }


    - (void)updateView {
     AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
     if (appDelegate.session.isOpen) {

    string = [NSString stringWithFormat:@"%@",
              appDelegate.session.accessToken];

    NSLog(@"string issss %@",string);
    NSString *urlstrng;
    if(flag == 1){
        urlstrng = [NSString stringWithFormat:@"https://graph.facebook.com/me?access_token=%@",
                    string];
        [self dataFetching:urlstrng];
        }


       } else {

    string = [NSString stringWithFormat:@"%@",
              appDelegate.session.accessToken];
    NSString *urlstrng;
    if(flag == 1){
        urlstrng = [NSString stringWithFormat:@"https://graph.facebook.com/me?access_token=%@",
                    string];
        [self dataFetching:urlstrng];
       }
       }
       }

     -(void)dataFetching:(NSString*)strng1{

       NSURL *url = [NSURL URLWithString:strng1];
       ProfileConnector *obj = [[ProfileConnector alloc] init];
      obj.delegate1 = self;
       [obj parsingJson:url];

       }


       - (BOOL)shouldAutorotateToInterfaceOrientation:   (UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
     }




     - (void) performPublishAction:(void (^)(void)) action {
   if ([FBSession.activeSession.permissions indexOfObject:@"publish_actions"] ==  NSNotFound) {
     [FBSession.activeSession reauthorizeWithPublishPermissions:[NSArray  arrayWithObject:@"publish_actions"]
                                                defaultAudience:FBSessionDefaultAudienceFriends
                                             completionHandler:^(FBSession *session,  NSError *error) {
     if (!error) {
                     action();
                                                 }
                                             }];
       } else {
    action();
       }

        }



        }

       @end
4

1 回答 1

1

由于您使用的是 3.1 版本的 Facebook SDK,openActiveSessionWithPermissions:allowLoginUI:completionHandler:因此不应该使用,而且旧的做法似乎不再适用;来自3.1 迁移文档

...您将需要删除 openActiveSessionWithPermissions:allowLoginUI:completionHandler: 的使用并将其替换为 openActiveSessionWithReadPermissions:allowLoginUI:completionHandler: (或者更简单地说,openActiveSessionWithAllowLoginUI)。

稍后,当您的应用需要发布回 Facebook 时,您应该使用 reauthorizeWithPublishPermissions:defaultAudience:completionHandler: 来寻求额外的权限。

迁移文档中提供了更多详细信息。

于 2013-01-01T18:37:58.383 回答