2012-12-20 3 views
-1

나는 페이스 북으로 페이스 북과 페이스 북을 공유하는 옵션이있다. (페이스 북 사용자의 사용자 아이디와 서버 사이드 개발자는 포스트 파트를 수행한다.) 페이스 북에서 로그인하는 동안 사용자 ID를 가져갈 수 있습니다. 하지만 문제는 - 사용자가 Facebook에서 인증 한 후 "사용자를 대신하여 게시"가 응용 프로그램에 포함되지 않음 (ios6 SDK를 사용 중입니다) Facebook에서 내 앱을 만들었습니다. 그래프에서 public_action을 확인했습니다.) 페이 스북 개발자 페이지에서 제공되는 자습서 (맛있습니다)를 읽었지만 만들 수는 없었습니다.아이폰 앱의 페이스 북

다음은 내 코드입니다. 오류 또는 누락 된 항목을 찾으면 부품, 그

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 
을 취소 좀 도와주세요

- (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 
+0

처음에는 "내 서버 측 개발자가 게시 부분을 수행합니다."라고 말했습니다. 그런 다음 당신을 대신해서 "앱에 오지 않습니다"라고 말합니다. 당신은 실제로 무엇을 원합니까? – Atif

+0

인증 된 경우 (사용자를 대신하여 게시) 서버 측에서 사용자 FB 계정에 게시 할 수 있습니다 –

답변

1

당신은 페이스 북 SDK의 3.1 버전을 사용하고 있기 때문에, openActiveSessionWithPermissions:allowLoginUI:completionHandler:이 사용하고 그것을하는 옛날 방식이 더 이상 작동 될 것 같지 않습니다 안됩니다 InviteFriendViewController.m; 3.1 migration documentation에서; allowLoginUI : completionHandler을 :

... 당신이 openActiveSessionWithPermissions의 사용을 제거해야합니다 및 openActiveSessionWithReadPermissions로 교체 : allowLoginUI : completionHandler를 (또는 더 간단하게, openActiveSessionWithAllowLoginUI).

나중에 앱이 Facebook에 다시 게시해야하는 경우 reauthorizeWithPublishPermissions : defaultAudience : completionHandler :를 사용하여 추가 권한을 찾아야합니다.

더욱 자세한 내용은 migration docs에서 확인할 수 있습니다.

관련 문제