如果您想将猫中的值作为列获取,请尝试使用pyrebase,在cmd / anaconda prompt 使用pip install pyrebase(如果您没有设置PIP 或Python,则稍后会首选)环境路径。安装后:
import pyrebase
config {"apiKey": yourapikey
"authDomain": yourapidomain
"databaseURL": yourdatabaseurl,
"storageBucket": yourstoragebucket,
"serviceAccount": yourserviceaccount
}
注意:您可以在 Firebase 的控制台中找到以上所有信息:
https://console.firebase.google.com/project/ >>> 你的项目 >>> 点击图标“”,标签为“将 firebase 添加到你的网络应用程序”
回到代码...
制作一个简洁的定义,以便您可以将其存储到 py 文件中:
def connect_firebase():
# add a way to encrypt those, I'm a starter myself and don't know how
username: "usernameyoucreatedatfirebase"
password: "passwordforaboveuser"
firebase = pyrebase.initialize_app(config)
auth = firebase.auth()
#authenticate a user > descobrir como não deixar hardcoded
user = auth.sign_in_with_email_and_password(username, password)
#user['idToken']
# At pyrebase's git the author said the token expires every 1 hour, so it's needed to refresh it
user = auth.refresh(user['refreshToken'])
#set database
db = firebase.database()
return db
好的,现在将它保存到一个整洁的.py 文件中
接下来,在您的新笔记本或主 .py 中,您将导入 这个我们将调用的新 .py 文件 auth.py 从现在开始...
from auth import *
# add do a variable
db = connect_firebase()
#and now the hard/ easy part that took me a while to figure out:
# notice the value inside the .child, it should be the parent name with all the cats keys
values = db.child('cats').get()
# adding all to a dataframe you'll need to use the .val()
data = pd.DataFrame(values.val())
就是这样,print(data.head()) 检查值/列是否在预期的位置。