• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 使用我自己的 UIButton 获取用户 Facebook 信息

[复制链接]
菜鸟教程小白 发表于 2022-12-12 23:12:13 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我正在尝试创建一个 Facebook 连接按钮,我需要在连接时为此获取 FBGraphUser。我的 Button 上有以下代码:

-(IBAction)fbButtonClickHandlerid)sender {
    mainDelegate = (AppDelegate*)[[UIApplication sharedApplication]delegate];

  if (mainDelegate.fbSession.isOpen) { 
    [mainDelegate.fbSession closeAndClearTokenInformation]; // FB delog
  }
  else {
    if (mainDelegate.fbSession.state != FBSessionStateCreated) {
        mainDelegate.fbSession = [[FBSession alloc] initWithPermissions:[NSArray arrayWithObjects"email", @"publish_actions", @"user_birthday",nil]];
    }
     // loggin on facebook
    [mainDelegate.fbSession openWithCompletionHandler:^(FBSession *session,
                                                     FBSessionState status,
                                                     NSError *error) {

        [fbButton setTitle:[self updateFbButtonLabel] forState:UIControlStateNormal];
        // reading the documentation i'm trying this to get the FBGraphUser
        if(session.isOpen) {
            [FBRequestConnection startForMeWithCompletionHandler:^(FBRequestConnection *connection, id<FBGraphUser> user, NSError *error) {

                  if (!error) {
                    NSString *userInfo = @"";

                    // Example: typed access (name)
                    // - no special permissions required
                    userInfo = [userInfo
                                stringByAppendingString:
                                [NSString stringWithFormat"Name: %@\n\n",
                                 user.name]];

                    // Example: typed access, (birthday)
                    // - requires user_birthday permission
                    userInfo = [userInfo
                                stringByAppendingString:
                                [NSString stringWithFormat"Birthday: %@\n\n",
                                 user.birthday]];
                    // Display the user info
                    NSLog(@"%@", userInfo);
                  }
                  NSLog(@" error: %@" , error);
                }];
        }
       }
    }];
}
}

问题是当我调用 startForMeWithCompletionHandler 时它失败了:

 错误:HTTP 状态码:400
    FBSDKLog:响应:
    操作无法完成。 (com.facebook.sdk 错误 5。)
    (无效的)
    错误:错误域=com.facebook.sdk 代码=5“操作无法完成。
    (com.facebook.sdk 错误 5。)“UserInfo=0x925f760 {com.facebook.sdkarsedJSONResponseKey=
    {type = 可变字典,count = 2,
     条目 =>
      1:{内容=“代码”}=
      {值 = +400,类型 = kCFNumberSInt32Type}
      2 : {contents = "body"} = {type = mutable dict, count = 1,
       条目 =>
       11 : {contents = "error"} = {type = mutable dict, count = 3,
       条目 =>
    2 : {contents = "type"} = {contents = "OAuthException"}
        3 : {contents = "message"} = {contents = "必须使用事件访问 token 来查询有关信息
       当前用户。"}
    6 : {内容 = "代码"} = 2500

我错过了什么吗?



Best Answer-推荐答案


显然,FBRequestConnection 在 FBSession 中使用了一个名为 active session 的变量来使其在之后工作

 [mainDelegate.fbSession openWithCompletionHandler:^(FBSession *session,
                                                     FBSessionState status,
                                                     NSError *error) {

放:

FBSession.activeSession = session;

关于ios - 使用我自己的 UIButton 获取用户 Facebook 信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12951135/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap