【问题标题】:Get firebase key after push ( python2.7 )推送后获取firebase密钥(python2.7)
【发布时间】:2017-12-20 18:00:48
【问题描述】:

我正在使用 Python 2.7 和 Pyrebase(作为与我的 Firebase 数据库通信的包)。 我试图在我的数据库中获取新推送对象的key()。我用 node.js 做了很多次,但我需要一些帮助才能用 Python 2.7 做这件事 这是我的 API:

@APP.route('/api/product', methods = ['POST'])
def products():
    product_details = {
        "title": request.form['title'],
        "description": request.form['description']
    }
    new_product = DB.push("product").push(product_details)
    print new_product.get().key()

    return json.dumps(apiResponse.success(product_details))

对象将被插入到数据库中,但我不知道如何获取它的密钥。 在 node.js 中,我会使用一个 Promise,插入后,我会得到密钥。

P.S:我不能使用.ref(),因为我使用Pyrebase

【问题讨论】:

    标签: python python-2.7 firebase-realtime-database callback key


    【解决方案1】:

    我将此添加到我的代码中: rec = DB.child("product").push(product_details) 这样,我就可以拿到钥匙了。所以,我的代码现在看起来像这样:

    @APP.route('/api/product', methods = ['POST'])
    def products():
        product_details = {
            "title": request.form['title'],
            "description": request.form['description']
        }
      DB.child("product").push(product_details)
      rec = DB.child("product").push(product_details)   
      DB.child("users").child(owner_details['uid']).child('products').update({rec['name']: "true"})
      return json.dumps(apiResponse.success(product_details))
    

    【讨论】:

      猜你喜欢
      • 2023-04-05
      • 1970-01-01
      • 2018-01-02
      • 2021-07-14
      • 1970-01-01
      • 2019-05-09
      • 2019-03-20
      • 1970-01-01
      • 2019-03-01
      相关资源
      最近更新 更多