Guest User

Untitled

a guest
Apr 24th, 2018
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. # 引用必要套件
  2. import firebase_admin
  3. from firebase_admin import credentials
  4. from firebase_admin import firestore
  5.  
  6. # 引用私密金鑰
  7. # path/to/serviceAccount.json 請用自己存放的路徑
  8. cred = credentials.Certificate('serviceAccount.json')
  9.  
  10. # 初始化firebase,注意不能重複初始化
  11. firebase_admin.initialize_app(cred)
  12.  
  13. # 初始化firestore
  14. db = firestore.client()
  15.  
  16. doc = {
  17. 'name': "帽子哥",
  18. 'email': "abc@gmail.com"
  19. }
  20.  
  21. # 語法
  22. # collection_ref = db.collection("集合路徑")
  23.  
  24. collection_ref = db.collection("pyradise_students")
  25.  
  26. # collection_ref提供一個add的方法,input必須是文件,型別是dictionary
  27.  
  28. collection_ref.add(doc)
Add Comment
Please, Sign In to add comment