<p>如果要将cats中的值作为列获取,请尝试使用<a href="https://github.com/thisbejim/Pyrebase" rel="nofollow noreferrer">pyrebase</a>,在<code>cmd</code>/<code>anaconda prompt</code>使用<code>pip install pyrebase</code>(如果没有在环境路径上设置PIP或Python,则稍后会首选)。安装后:</p>
<pre><code>import pyrebase
config {"apiKey": yourapikey
"authDomain": yourapidomain
"databaseURL": yourdatabaseurl,
"storageBucket": yourstoragebucket,
"serviceAccount": yourserviceaccount
}
</code></pre>
<p><strong>注意:</strong>您可以在Firebase的控制台上找到上述所有信息:
<a href="https://console.firebase.google.com/project/" rel="nofollow noreferrer">https://console.firebase.google.com/project/</a>>>>>您的项目>>>>单击带有“将firebase添加到web应用程序”标记的图标“<;'/>;”</p>
<p>回到代码。。。</p>
<p>创建一个整洁的定义,以便将其存储到py文件中:</p>
<pre><code>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
</code></pre>
<p>好的,现在把它保存到一个整洁的<code>.py</code>文件中</p>
<p>接下来,在您的新笔记本或main.py上,您将导入这个新的.py文件,从现在起我们将调用它</strong><code>auth.py</code>。。。</p>
<pre><code>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())
</code></pre>
<p>就是这样,<code>print(data.head())</code>来检查值/列是否在预期的位置。</p>