无法从facebook获取iOS电子邮件和生日

无法从facebook获取iOS电子邮件和生日,ios,iphone,Ios,Iphone,标题: #import <UIKit/UIKit.h> #import <FacebookSDK/FacebookSDK.h> @interface ViewController : UIViewController<UITextFieldDelegate> { IBOutlet UITextField *update; NSString *status; } @property (nonatomic, copy) IBOutlet NSS

标题:

#import <UIKit/UIKit.h>
#import <FacebookSDK/FacebookSDK.h>

@interface ViewController : UIViewController<UITextFieldDelegate>
{
    IBOutlet UITextField *update;
    NSString *status;

}
@property (nonatomic, copy) IBOutlet NSString *status;
@end
#导入
#进口
@界面ViewController:UIViewController
{
IBOutlet UITextField*更新;
NSString*状态;
}
@属性(非原子,复制)IBNSSTRING*状态;
@结束
.m文件:

#import "ViewController.h"

@interface ViewController ()
@property (strong, nonatomic) IBOutlet UIButton *buttonPostStatus;
@property (strong, nonatomic) id<FBGraphUser> loggedInUser;
@property (strong, nonatomic) IBOutlet UILabel *labelFirstName;
@property (strong,nonatomic) IBOutlet UITextField *update;
@property (strong,nonatomic) IBOutlet UILabel *dob;
@property (strong,nonatomic) IBOutlet UILabel *profilename;

- (IBAction)postStatusUpdateClick:(UIButton *)sender;
@end

@implementation ViewController


@synthesize buttonPostStatus = _buttonPostStatus;
@synthesize loggedInUser = _loggedInUser;
@synthesize labelFirstName = _labelFirstName;
@synthesize update;
@synthesize dob;
@synthesize profilename;


- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    FBLoginView *loginview = [[FBLoginView alloc] init];

    loginview.frame = CGRectOffset(loginview.frame, 5, 5);
    if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) {
        loginview.frame = CGRectOffset(loginview.frame, 5, 25);
    }
    loginview.delegate = self;
    self.labelFirstName = nil;
    self.loggedInUser = nil;

    [self.view addSubview:loginview];

    [loginview sizeToFit];

    NSString *status = update.text;

}

- (void)viewDidUnload {
    self.buttonPostStatus = nil;


    [super viewDidUnload];
}

- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView
                            user:(id<FBGraphUser>)user {

    self.labelFirstName.text = [NSString stringWithFormat:@"Hello %@ %@", user.first_name, user.last_name ];
    self.loggedInUser = user;
    self.dob.text= [NSString stringWithFormat:@"Birthday- %@", user.birthday];
    NSLog(user.birthday);
    NSLog(self.labelFirstName.text);
    //NSLog(user.dob);

    }

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)loginView:(FBLoginView *)loginView handleError:(NSError *)error {
    NSLog(@"FBLoginView encountered an error=%@", error);
}

- (void) performPublishAction:(void (^)(void)) action {
    // we defer request for permission to post to the moment of post, then we check for the permission
    if ([FBSession.activeSession.permissions indexOfObject:@"publish_actions"] == NSNotFound) {
        // if we don't already have the permission, then we request it now
        [FBSession.activeSession requestNewPublishPermissions:@[@"publish_actions"]
                                              defaultAudience:FBSessionDefaultAudienceFriends
                                            completionHandler:^(FBSession *session, NSError *error) {
                                                if (!error) {
                                                    action();
                                                } else if (error.fberrorCategory != FBErrorCategoryUserCancelled){
                                                    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Permission denied"
                                                                                                        message:@"Unable to get permission to post"
                                                                                                       delegate:nil
                                                                                              cancelButtonTitle:@"OK"
                                                                                              otherButtonTitles:nil];
                                                    [alertView show];
                                                }
                                            }];
    } else {
        action();
    }

}
- (IBAction)postStatusUpdateClick:(UIButton *)sender {

    NSURL *urlToShare = [NSURL URLWithString:@"htts.facebook.com/ios"];

    FBAppCall *appCall = [FBDialogs presentShareDialogWithLink:urlToShare
                                                          name:@"Hello Facebook"
                                                       caption:nil
                                                   description:@"The 'Hello Facebook' sample application showcases simple Facebook integration."
                                                       picture:nil
                                                   clientState:nil
                                                       handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
                                                           if (error) {
                                                               NSLog(@"Error: %@", error.description);
                                                           } else {
                                                               NSLog(@"Success!");
                                                           }
                                                       }];

            [self performPublishAction:^{
                FBRequestConnection *connection = [[FBRequestConnection alloc] init];

                connection.errorBehavior = FBRequestConnectionErrorBehaviorReconnectSession
                | FBRequestConnectionErrorBehaviorAlertUser
                | FBRequestConnectionErrorBehaviorRetry;

                [connection addRequest:[FBRequest requestForPostStatusUpdate:update.text]
                     completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {

                         [self showAlert:update.text result:result error:error];
                         self.buttonPostStatus.enabled = YES;
                     }];
                [connection start];

                self.buttonPostStatus.enabled = NO;
            }];
        }


- (void)showAlert:(NSString *)message
           result:(id)result
            error:(NSError *)error {

    NSString *alertMsg;
    NSString *alertTitle;
    if (error) {
        alertTitle = @"Error";
        if (error.fberrorUserMessage && FBSession.activeSession.isOpen) {
            alertTitle = nil;

        } else {
            // Otherwise, use a general "connection problem" message.
            alertMsg = @"Operation failed due to a connection problem, retry later.";
        }
    } else {
        NSDictionary *resultDict = (NSDictionary *)result;
        alertMsg = [NSString stringWithFormat:@"Successfully posted '%@'.", update.text];
        NSString *postId = [resultDict valueForKey:@"id"];
        if (!postId) {
            postId = [resultDict valueForKey:@"postId"];
        }
        if (postId) {
            alertMsg = [NSString stringWithFormat:@"%@\nPost ID: %@", alertMsg, postId];
        }
        alertTitle = @"Ho Gya!!";
    }

    if (alertTitle) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:alertTitle
                                                            message:alertMsg
                                                           delegate:nil
                                                  cancelButtonTitle:@"OK"
                                                  otherButtonTitles:nil];
        [alertView show];
    }
}

@end
#导入“ViewController.h”
@界面视图控制器()
@属性(强,非原子)IBUIButton*buttonPostStatus;
@属性(强,非原子)id loggedInUser;
@属性(强,非原子)IBUILabel*labelFirstName;
@属性(强,非原子)IBOutlet UITextField*更新;
@性质(强,非原子)IBUILabel*dob;
@属性(强,非原子)IBUILabel*profilename;
-(iAction)postStatusUpdateClick:(ui按钮*)sender;
@结束
@实现视图控制器
@合成buttonPostStatus=\u buttonPostStatus;
@综合loggedInUser=\u loggedInUser;
@合成labelFirstName=_labelFirstName;
@综合更新;
@合成dob;
@综合档案名称;
-(无效)viewDidLoad
{
[超级视图下载];
//加载视图后,通常从nib执行任何其他设置。
FBLoginView*loginview=[[FBLoginView alloc]init];
loginview.frame=CGRectOffset(loginview.frame,5,5);
if([self respondsToSelector:@selector(setEdgesForExtendedLayout:)])){
loginview.frame=CGRectOffset(loginview.frame,5,25);
}
loginview.delegate=self;
self.labelFirstName=nil;
self.loggedInUser=nil;
[self.view addSubview:loginview];
[loginview sizeToFit];
NSString*状态=update.text;
}
-(无效)视图卸载{
self.buttonPostStatus=nil;
[超级视频下载];
}
-(无效)loginView蚀刻教育信息:(FBLoginView*)loginView
用户:(id)用户{
self.labelFirstName.text=[NSString stringWithFormat:@“Hello%@@”,user.first\u name,user.last\u name];
self.loggedInUser=用户;
self.dob.text=[NSString stringWithFormat:@“生日-%@”,user.birth];
NSLog(用户生日);
NSLog(self.labelFirstName.text);
//NSLog(user.dob);
}
-(无效)未收到记忆警告
{
[超级记忆警告];
//处置所有可以重新创建的资源。
}
-(无效)loginView:(FBLoginView*)loginView句柄错误:(N错误*)错误{
NSLog(@“FBLoginView遇到错误=%@”,错误);
}
-(作废)执行公告:(作废)(作废)行为{
//我们将发布许可的请求推迟到发布时,然后检查许可
if([FBSession.activeSession.permissions indexOfObject:@“发布操作”]==NSNotFound){
//如果我们还没有获得许可,那么我们现在就申请
[FBSession.activeSession requestNewPublishPermissions:@[@“发布操作”]
默认观众:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession*会话,NSError*错误){
如果(!错误){
动作();
}else if(error.fberrorCategory!=FBErrorCategoryUserCancelled){
UIAlertView*alertView=[[UIAlertView alloc]initWithTitle:@“权限被拒绝”
消息:@“无法获得发布权限”
代表:无
取消按钮:@“确定”
其他按钮:无];
[警报视图显示];
}
}];
}否则{
动作();
}
}
-(iAction)postStatusUpdateClick:(UIButton*)发件人{
NSURL*urlToShare=[NSURL URLWithString:@“htts.facebook.com/ios”];
FBAppCall*appCall=[FBDialogs presentShareDialogWithLink:urlToShare
姓名:@“你好,Facebook”
描述:无
description:@“Hello Facebook”示例应用程序展示了简单的Facebook集成。”
图片:无
客户状态:无
处理程序:^(FBAppCall*调用,NSDictionary*结果,NSError*错误){
如果(错误){
NSLog(@“错误:%@”,错误描述);
}否则{
NSLog(@“成功!”);
}
}];
[自动执行发布:^{
FBRequestConnection*连接=[[FBRequestConnection alloc]init];
connection.errorBehavior=FBRequestConnectionErrorBehaviorReconnectSession
|FBRequestConnectionErrorBehaviorAlertUser
|FBRequestConnectionErrorBehaviorMetry;
[连接添加请求:[FBRequestForPostStatusUpdate:update.text]
completionHandler:^(FBRequestConnection*连接,id结果,NSError*错误){
[自显示警报:更新。文本结果:结果错误:错误];
self.buttonPostStatus.enabled=是;
}];
[连接启动];
self.buttonPostStatus.enabled=否;
loginview.readPermissions=@[@"email"];