FBSDK (New Facebook SDK 4.0) Implementation is not working for Login with Facebook

匿名 (未验证) 提交于 2019-12-03 02:18:01

问题:

I am using this following block which is mentioned in Facebook Developer. But when my App callbacks from Browser then it is always returning Cancelled result.

FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init]; [login logInWithReadPermissions:@[@"email"]              handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {   if (error) {         // Process error    }   else if (result.isCancelled) {         // Handle cancellations    }    else {        // If you ask for multiple permissions at once, you        // should check if specific permissions missing        if ([result.grantedPermissions containsObject:@"email"]) {         // Do work        }   }  }]; 

this update comes on 25 March 15,

If anyone used this then please share it with me.

Reference : https://developers.facebook.com/docs/ios/getting-started

回答1:

You must add the following method in your appDelegate

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {     return [[FBSDKApplicationDelegate sharedInstance] application:application                                                           openURL:url                                                 sourceApplication:sourceApplication                                                        annotation:annotation]; } 

If the above method is not present into AppDelegate then it results into cancelled state.

Refer to : https://developers.facebook.com/docs/ios/getting-started#startcoding



回答2:

You use this simple block with your expected requirements

if ([FBSDKAccessToken currentAccessToken]) {       [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil]                  startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id user, NSError *error)        {            if (!error)            {             //  NSDictionary *dictUser = (NSDictionary *)user;             // This dictionary contain user Information which is possible to get from Facebook account.            }         }]; } 

Access Token you will get only and only after successfully login

Hope this will help you



回答3:

To get user profile try this

if ([FBSDKAccessToken currentAccessToken])                 {                     [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil]                      startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id user, NSError *error)                      {                          if (!error) {                              NSDictionary *dictUser = (NSDictionary *)user;                              self.txfName.text      = [dictUser objectForKeyNotNull:@"name"];                              self.txfEmail.text     = [dictUser objectForKeyNotNull:@"email"];                              self.txfUserName.text  = [[dictUser objectForKey:@"first_name"] lowercaseString];                              NSLog(@"image : https://graph.facebook.com/%@/picture?type=small",[dictUser objectForKeyNotNull:@"id"]);                          }                      }];                 } 

Hope this would help you



回答4:

You cant get Email id from Facebook Login....why???

If your Facebook account registered using "Mobile Number", and you do not have Email in same account.

Check this scenario. This might be happening, We cant blame for it to FBSDK.

Hope this will clear some points.



回答5:

For me, the following line caused isCancelled to always be true... idk why

[login logInWithReadPermissions:@[@"public_profile", @"email", @"gender"]  

After changing to this... it worked

[login logInWithReadPermissions:@[@"public_profile"]  


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!