使用Facebook凭据登录Parse.com的问题

时间:2016-01-09 16:45:45

标签: ios objective-c facebook facebook-graph-api parse-platform

我根据Parse.com网站的建议创建了一个Facebook帐户,设置了Parse.com应用程序并开发了iOS应用程序。我按照所有步骤在info.plist文件和app delegate类中进行了更改 下面是我的代码,我试图逐行调试它。我注意到FB要求用户许可,即使在接受后,也不会再采取进一步行动。

- (IBAction)fblogin:(FBSDKLoginButton *)sender {

    NSArray *permissions = @[@"public_profile", @"email"];

    [PFFacebookUtils logInInBackgroundWithReadPermissions:permissions block:^(PFUser *user, NSError *error) {
        if (error) {
            UIAlertView *alertVeiw = [[UIAlertView alloc] initWithTitle:@"Sorry" message:[error.userInfo objectForKey:@"error"] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];

            [alertVeiw show];
        } else {

            [self loadData];
            [self.navigationController popToRootViewControllerAnimated:NO];

        }
    }];

}

-(void)loadData{

    FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"email, public_profile"}];
    [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error)
     {
         if (!error)
         {
             // NSDictionary *userData = (NSDictionary *)result;

//             NSString *first = [result objectForKey:@"first_name"];
//             NSString *last = [result objectForKey:@"last_name"];
//             NSString *username = [NSString stringWithFormat:@"%@.%@", first, last];
             NSString *name = [result objectForKey:@"name"];
             NSString *email = [result objectForKey:@"email"];

             PFUser *userFb = [PFUser currentUser];

             [userFb setObject:name forKey:@"username"];
             [userFb setObject:email forKey:@"email"];
             [userFb saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {

                 if (error)
                 {
                     UIAlertView *alertVeiw = [[UIAlertView alloc] initWithTitle:@"Sorry" message:[error.userInfo objectForKey:@"error"] delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];

                     [alertVeiw show];
                 } else {

                     [[PFInstallation currentInstallation] setObject:[PFUser currentUser].objectId forKey:@"userId"];
                     [[PFInstallation currentInstallation] saveInBackground];
                     //   [self.navigationController popToRootViewControllerAnimated:NO];
                 }
             }];
         }

     }];
}

我无法理解为什么它不起作用。

将导入的框架导入.m

#import "LoginViewController.h"
#import <Parse/Parse.h>
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>
#import <TwitterKit/TwitterKit.h>
#import <ParseFacebookUtilsV4/PFFacebookUtils.h>
#import "InboxViewController.h"
#import "MBProgressHUD.h"

以上是我唯一的登录代码,我不知道为什么它不起作用。当我第一次添加并更改代码时,它将登录并提供随机用户名。然后当我继续尝试不同的方法并最终以上面的方法结束时,它停止了登录

0 个答案:

没有答案