在实时数据库中将Facebook朋友ID映射到Firebase uid [英] Mapping Facebook friend id to Firebase uid in realtime database

查看:112
本文介绍了在实时数据库中将Facebook朋友ID映射到Firebase uid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将Facebook朋友ID映射到实时数据库中的Firebase uid?据我了解,Firebase的uid与Facebook的id不同.

How do I map a Facebook friend id to a Firebase uid in the realtime database? It's my understanding that the Firebase uid is not the same as a Facebook id.

我当前的用户流是通过Facebook sdk登录到Facebook,然后将Facebook访问令牌传递到Firebase sdk以使用Firebase登录.

My current user flow is logging into Facebook through the Facebook sdk, and then passing the facebook access token to the Firebase sdk to login with Firebase.

我的最终目标是存储游戏分数,以便用户可以看到他们的朋友以及他们自己的分数.我不想要求每个玩家获得每个分数并在客户端上过滤此信息.我宁愿向X个查询发送X个朋友的查询,而只请求所需的分数.

My end goal is to store game scores so that a user can see the scores of their friends as well as their own. I do not want to request every score for every player and filter for this information on the client. I would rather send X queries for X amount of friends and only request the scores desired.

推荐答案

不确定downvote是做什么用的,但这是我最终使用的解决方案.

Not sure what the downvote was for, but here is the solution I ended up using.

通过facebookId(而不是firebaseId)存储分数可以查找朋友的分数,因为无论如何将facebookId映射到firebaseId都必须将其存储在数据库中.看起来像这样:

Storing the scores by facebookId instead of firebaseId allows the lookup of scores of friends, since a facebookId can't be mapped to a firebaseId without storing it in the database anyway. It looks like this:

facebookUsers {
  facebookId {
    "firebaseId" : firebaseId,
    "scores" : {
      level : score,
    }
  }
}

此结构可让您轻松地按facebookId查找分数,并在其他操作需要时将facebookId映射到firebaseId.

This structure allows you to easily lookup scores by facebookId, and also map facebookIds to firebaseIds if desired for other operations.

要保存分数:

FirebaseDatabase.DefaultInstance
  .GetReference("facebookUsers")
  .Child(facebookId)
  .Child("scores")
  .Child(level)
  .SetValueAsync(score);

要查找分数:

FirebaseDatabase.DefaultInstance
  .GetReference("facebookUsers")
  .Child(facebookId)
  .Child("scores")
  .Child(level)
  .GetValueAsync();

要限制基于facebookId的写入,请使用以下规则:

To restrict writes based on facebookId, use the following rules:

{
  "rules": {
    ".read": "auth != null",
    "facebookUsers": {      
      "$facebookId" : {
        ".write": "data.child('firebaseId').val() == auth.uid || (!data.exists() && newData.child('firebaseId').val() == auth.uid)",
      }
    }
  }
}

希望这可以帮助某人,而不是投降票.

Hopefully this helps someone more than a downvote.

这篇关于在实时数据库中将Facebook朋友ID映射到Firebase uid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆