iOS FB SDK访问令牌是零

发布于 2025-01-24 11:10:52 字数 1348 浏览 0 评论 0原文

我使用的是fbsdkcorekit和fbsdkloginkit v13.1

我的应用程序中有一个fb登录按钮,其中包含以下处理程序:

- (void)  loginButton:(FBSDKLoginButton *)loginButton
didCompleteWithResult:(FBSDKLoginManagerLoginResult *)result
                error:(NSError *)error{
    if (error || (result && result.isCancelled)) {
      return;
    }
    [self loginWithFB];
}

该代码的此部分正常工作,按钮状态也更改为log成功后>登录,但是当我想提出图形请求时,它们会失败,因为它没有fb访问令牌([fbsdkaccesstoken currentAccessToken]是nil

- (void) loginWithFB {
    NSString *fbAccessToken = [[FBSDKAccessToken currentAccessToken] tokenString];

    [[[FBSDKGraphRequest alloc]
      initWithGraphPath:@"me"
      parameters:@{@"fields": @"id"}
      tokenString:fbAccessToken
      version:nil
      HTTPMethod:@"GET"
     ]
     startWithCompletion:^(id<FBSDKGraphRequestConnecting> connection, id result, NSError *error) {
        if (!error) {
            ...
        } else {
            ...
        }
     }];
}

我不确定是什么原因导致了这一点,boottrap(appdelegate) ,正确设置FB SDK的设置(检查了比我想要的更多),但是 docs 明确指出,当按钮登录状态时,应提供CurrentAccessToken。 (fbsdkloginmanager直接与[FBSDKACCESSTOKEN CurrentAccessToken]合作,并在成功的授权下设置“ CurrentAccessToken”(或在logout中设置零)。)。)

I'm using FBSDKCoreKit and FBSDKLoginKit v13.1

I have a FB Login Button in my application with the following handler:

- (void)  loginButton:(FBSDKLoginButton *)loginButton
didCompleteWithResult:(FBSDKLoginManagerLoginResult *)result
                error:(NSError *)error{
    if (error || (result && result.isCancelled)) {
      return;
    }
    [self loginWithFB];
}

This part of the code works fine, the buttons state also changes to Log out after a successful login, however when I want to make graph requests they fail because it doesn't have a FB Access token ([FBSDKAccessToken currentAccessToken] is nil)

- (void) loginWithFB {
    NSString *fbAccessToken = [[FBSDKAccessToken currentAccessToken] tokenString];

    [[[FBSDKGraphRequest alloc]
      initWithGraphPath:@"me"
      parameters:@{@"fields": @"id"}
      tokenString:fbAccessToken
      version:nil
      HTTPMethod:@"GET"
     ]
     startWithCompletion:^(id<FBSDKGraphRequestConnecting> connection, id result, NSError *error) {
        if (!error) {
            ...
        } else {
            ...
        }
     }];
}

I am not sure what is causing this, the bootstrap (AppDelegate, plist, etc.) setup for the FB SDK is set up correctly (checked this more than I would like), but the docs clearly state that when the button has a logged in state, the currentAccessToken should be available.
(FBSDKLoginManager works directly with [FBSDKAccessToken currentAccessToken] and sets the "currentAccessToken" upon successful authorizations (or sets nil in case of logOut).)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文