[英]iOS: Login to Facebook through app
I'm trying to login to Facebook through my app using FBSDKLoginManager
. 我正在尝试使用FBSDKLoginManager
通过我的应用程序登录Facebook。 I'm asking for some permissions while logging. 我在记录时要求一些权限。 But every time i get the following error: 但每次我收到以下错误:
[11624:2243947] data----(null) [11624:2243947] Access Facebook page error:Error Domain=com.facebook.sdk.core Code=8 "The operation couldn't be completed. (com.facebook.sdk.core error 8.)" UserInfo=0x15eb2e80 {com.facebook.sdk:FBSDKErrorDeveloperMessageKey=Sorry, this feature isn't available right now: An error occurred while processing this request. [11624:2243947] data ----(null)[11624:2243947]访问Facebook页面错误:错误Domain = com.facebook.sdk.core Code = 8“操作无法完成。(com.facebook。 sdk.core错误8.)“UserInfo = 0x15eb2e80 {com.facebook.sdk:FBSDKErrorDeveloperMessageKey =对不起,此功能现在不可用:处理此请求时出错。 Please try again later., com.facebook.sdk:FBSDKGraphRequestErrorGraphErrorCode=2, com.facebook.sdk:FBSDKGraphRequestErrorCategoryKey=0} 请稍后再试.com.facebook.sdk:FBSDKGraphRequestErrorGraphErrorCode = 2,com.facebook.sdk:FBSDKGraphRequestErrorCategoryKey = 0}
Could anyone please help? 有人可以帮忙吗? This is the code that I've written: 这是我写的代码:
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithPublishPermissions:@[@"publish_actions"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
NSLog(@"data----%@",result.grantedPermissions);
if (error) {
// Process error
NSLog(@"Access Facebook page error:%@", 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:@"publish_actions"]) {
// Do work
NSLog(@" publish actions permission granted");
[login logInWithReadPermissions:@[@"user_likes",@"user_birthday"] 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:@"user_birthday"]) {
// Do work
NSLog(@"Permission 2: %@",result.grantedPermissions);
}
}
}];
}
}
}];
Login with Facebook SDK 4.x 使用Facebook SDK 4.x登录
Add following code to facebook login button click : 将以下代码添加到Facebook登录按钮单击:
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions:@[@"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
{
if (error)
{
// Error
}
else if (result.isCancelled)
{
// Cancelled
}
else
{
if ([result.grantedPermissions containsObject:@"email"])
{
[self getFBResult];
}
}
}];
Get Facebook Result Method : 获取Facebook结果方法:
-(void)getFBResult
{
if ([FBSDKAccessToken currentAccessToken])
{
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id, name, first_name, last_name, picture.type(large), email"}]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error)
{
NSLog(@"fb user info : %@",result);
}
else
{
NSLog(@"error : %@",error);
}
}];
}
}
You can change the fields of permissions as you want. 您可以根据需要更改权限字段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.