gpt4 book ai didi

ios - FBRequest requestForMe 没有响应

转载 作者:行者123 更新时间:2023-11-28 20:17:46 25 4
gpt4 key购买 nike

我正在关注 Facebook 开发者网站上的示例代码,但我无法获取我的姓名等信息。我正在使用这段代码:

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.


AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
if (!appDelegate.session.isOpen) {
NSLog(@"Session is not open");
// create a fresh session object
appDelegate.session = [[FBSession alloc] init];

// if we don't have a cached token, a call to open here would cause UX for login to
// occur; we don't want that to happen unless the user clicks the login button, and so
// we check here to make sure we have a token before calling open
if (appDelegate.session.state == FBSessionStateCreatedTokenLoaded) {
// even though we had a cached token, we need to login to make the session usable
[appDelegate.session openWithCompletionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
// we recurse here, in order to update buttons and labels
}];
}
} else {
NSLog(@"Session is open");

[[FBRequest requestForMe] startWithCompletionHandler:
^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if (!error) {
NSLog(@"logged in : %@, id: %@",user.name,user.id);
} else {
NSLog(@"error: %@", error);
}
}];
}

}

所以当 session 打开时,我看到这个输出:

Session is open
error: Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0x1fd60620 {com.facebook.sdk:ParsedJSONResponseKey={
body = {
error = {
code = 2500;
message = "An active access token must be used to query information about the current user.";
type = OAuthException;
};
};
code = 400;
}, com.facebook.sdk:HTTPStatusCode=400}

在 facebook 应用程序页面上,我将 AppId 设置为 0,因为它尚未上传。 BundleId 设置正确。

我缺少什么或有其他方法吗?

最佳答案

您应该通过调用

将您的 appDelegate.session 设置为事件 session
[FBSession setActiveSession:appDelegate.session]; 

当你打开它的时候。

这是因为 FBRequest 的 requestForMe 方法使用事件 session (如文档中所述)。

关于ios - FBRequest requestForMe 没有响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17252903/

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