gpt4 book ai didi

ios - 在 ios 中获取好友列表时,Facebook SDK Error Domain=com.facebook.sdk Code=5

转载 作者:可可西里 更新时间:2023-11-01 06:15:08 24 4
gpt4 key购买 nike

我是 iOS 应用程序开发的新手。我想学习在 ios 中集成 facebook 和获取好友列表。

我遵循 git hub 代码 https://github.com/facebook/facebook-ios-sdk/tree/master/samples/FriendPickerSample

然后按照所有步骤进行操作。我的代码是:

- (IBAction)friendPicker:(id)sender {


if (!FBSession.activeSession.isOpen)
{
// permission : [NSArray arrayWithObjects:@"email", @"read_friendlists", @"user_photos", @"user_events", nil]
[FBSession openActiveSessionWithReadPermissions:nil allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
if(error)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];

}
else if (session.isOpen)
{
// [FBSession setActiveSession:session];
[self friendPicker:sender];
}
}];
return;
}

if(FBSession.activeSession.isOpen)
{
FBRequest* friendsRequest = [FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary* result,
NSError *error) {
if(error)
{
NSLog(@"error : %@",error);
}
else
{

NSArray* friends = [result objectForKey:@"data"];
NSLog(@"total array : %@",result);
NSLog(@"Found: %i friends", friends.count);
for (NSDictionary<FBGraphUser>* friend in friends) {
NSLog(@"I have a friend named %@ with id %@", friend.name, friend.id);
}
}
}];


}
if(self.friendPickerController == nil)
{
self.friendPickerController = [[FBFriendPickerViewController alloc] init];

self.friendPickerController.title = @"Pick Friends";

self.friendPickerController.delegate = self;
}

[self.friendPickerController loadData];
[self.friendPickerController clearSelection];

[self presentViewController:self.friendPickerController animated:YES completion:nil];

}

-(void)fillTextAndDismiss:(NSString * )text
{
[self.selectedFrdView setText:text];

[self dismissViewControllerAnimated:YES completion:nil];
}

-(void)facebookViewControllerDoneWasPressed:(id)sender
{
NSMutableString *text = [[NSMutableString alloc] init];

for(id<FBGraphUser> user in self.friendPickerController.selection)
{
if([text length])
{
[text appendString:@", "];
}

[text appendString:user.name];
}

[self fillTextAndDismiss:text.length >0 ? text : @"<none>"];

}

-(void)facebookViewControllerCancelWasPressed:(id)sender
{
[self fillTextAndDismiss:@"<cancelled>"];
}

我还创建了 facebookAppId 并且 plist 文件也通过这个键更新。然后我也收到这个错误:

2014-05-12 14:21:27.043 fbFrndTest[2753:90b] error : Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0xb166450 {com.facebook.sdk:HTTPStatusCode=400, com.facebook.sdk:ParsedJSONResponseKey={
body = {
error = {
code = 100;
message = "(#100) Unknown fields: username.";
type = OAuthException;
};
};
code = 400;
}, com.facebook.sdk:ErrorSessionKey=<FBSession: 0xb521fd0, state: FBSessionStateOpen, loginHandler: 0x0, appID: 1481684055397512, urlSchemeSuffix: , tokenCachingStrategy:<FBSessionTokenCachingStrategy: 0xb523240>, expirationDate: 2014-07-11 05:48:12 +0000, refreshDate: 2014-05-12 07:26:43 +0000, attemptedRefreshDate: 0001-12-30 00:00:00 +0000, permissions:(
)>}

GitHUB 代码运行成功,但我的代码出错。

最佳答案

我相信你应该取消评论

//[FBSession setActiveSession:session];

还要仔细检查您是否已在“设置”下的模拟器上登录 Facebook

关于ios - 在 ios 中获取好友列表时,Facebook SDK Error Domain=com.facebook.sdk Code=5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23605289/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com