-1

私はiPhoneアプリに取り組んでいます。これには、投稿をフェイスブックと共有するためのオプションがあります(FacebookユーザーのユーザーIDを渡すだけで、サーバー側の開発者が投稿部分を行います)ユーザーIDを取得できますFacebookにログインしている間しかし問題は、ユーザーがFacebookから認証した後、「あなたに代わって投稿」がアプリに表示されないことです(私はios6 SDKを使用しています)(グラフからpublic_actionをチェックしてFacebookでアプリを作成しました) 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

InviteFriendViewController.h

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

InviteFriendViewController.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

Facebook SDK の 3.1 バージョンを使用しているため、openActiveSessionWithPermissions:allowLoginUI:completionHandler:使用することは想定されておらず、古い方法では機能していないようです。3.1 移行ドキュメントから;

... openActiveSessionWithPermissions:allowLoginUI:completionHandler: の使用を削除し、 openActiveSessionWithReadPermissions:allowLoginUI:completionHandler: (または、さらに単純に openActiveSessionWithAllowLoginUI) に置き換える必要があります。

後でアプリを Facebook に公開する必要がある場合は、reauthorizeWithPublishPermissions:defaultAudience:completionHandler: を使用して追加のアクセス許可を探す必要があります。

詳細については、移行ドキュメントを参照してください。

于 2013-01-01T18:37:58.383 に答える