axios在firebase上测试函数时返回错误400

vdgimpew  于 2023-01-20  发布在  iOS
关注(0)|答案(1)|浏览(106)

我想根据API响应更新firebase数据库中的一个字段,但是当我在google cloud中测试这个函数时,我得到了一个400错误。不确定我错过了什么:

import functions from 'firebase-functions';
import admin from 'firebase-admin';
import axios from 'axios';
const { initializeApp, credential: _credential, firestore} = admin;
admin.initializeApp();

const db = firestore();  

async function UpdateCountField() {
  console.log("Updating count task start point.");
  const query = db.collection('users').where('count', '==', '');
  return query.get().then(async snapshot => {
    console.log(query.get('erd'));
    let resptoken =  await axios.get(
        `https://api/${query.get('erd');
      result = resptoken.data;
    const promises = snapshot.docs.map(doc => doc.ref.update({ 'count': '${result}' }));
    return Promise.all(promises)
  })
  }
xdnvmnnf

xdnvmnnf1#

最后用一种简单得多的方法

const query = db.collection('users').where('count', '==', '').where('nou', '==', false).where('erd','!=','').get();
  const documents = (await query).docs;
  if ( documents.count == 0) {
    return;
  }
  for(const doc of documents) {
    let result = 0;
    try {
      let url = `https://api.../${doc.get('projectID')}`;
      let raspuns = await axios.get(url);
}
}

相关问题