Javascript Firebase云函数:无法通过Axios使用http.get请求的JSON输出
我无法在Firebase Cloud函数中使用外部Axios.get请求的JSON输出 当在Cloud Firestore中创建文档的部件被删除但在部署时导致错误时,以下函数在本地运行时提供所需的输出 TypeError:无法读取未定义的属性“user” 在axios.get.then.resultData/srv/index.js:13:52Javascript Firebase云函数:无法通过Axios使用http.get请求的JSON输出,javascript,node.js,firebase,google-cloud-platform,google-cloud-functions,Javascript,Node.js,Firebase,Google Cloud Platform,Google Cloud Functions,我无法在Firebase Cloud函数中使用外部Axios.get请求的JSON输出 当在Cloud Firestore中创建文档的部件被删除但在部署时导致错误时,以下函数在本地运行时提供所需的输出 TypeError:无法读取未定义的属性“user” 在axios.get.then.resultData/srv/index.js:13:52 这意味着.then在从.get检索JSON之前执行 我不明白为什么函数在本地运行或在emulator中运行时,而不是在实时部署中,会给出所需的输出第一个
这意味着.then在从.get检索JSON之前执行 我不明白为什么函数在本地运行或在emulator中运行时,而不是在实时部署中,会给出所需的输出第一个图像URL 常量函数=需要“firebase-functions”; const admin=需要“firebase-admin”; admin.initializeApp; const axios=require'axios'。默认值; exports.createEvent=functions.https.onRequestasync req,res=>{ axios .gethttps://www.instagram.com/cristiano/?__a=1 .thenresultData=>{ 让post=resultData.data.graphql.user.edge\u owner\u to\u timeline\u media.edges; img\u url=post[0]。node.display\u url; 如果发布[0].node.edge\u media\u到\u caption.edges[0]{ caption=post[0]。node.edge\u media\u to\u caption.edges[0]。node.text; } 让newDoc={ 邮政编码:parseInt0, url:img_url, 标题:标题 } 返回admin.firestore.collection'events'.doc.createnewDoc} .thenres.json{result:`Success`} .catcherr=>{ console.logerr; res.status500.senderr }; }
好的,我已经记录了resultData.data 我猜这意味着Instagram不允许从Firebase服务器请求,但允许从我的本地计算机请求 不允许。这意味着在您未登录时不允许请求 浏览器已登录,因此来自那里的请求将获得您期望的JSON Firebase服务器未登录,因此来自该服务器的请求会收到错误消息
您需要登录才能获取数据。介绍了如何执行此操作。这意味着.then在从.get检索JSON之前执行。-不,没有。a这不可能发生b如果它没有JSON,那么它将是未定义的resultData,而不是resultData.data.GraphQl可能您遇到了错误状态,可能是权限问题,您应该进行一些调试,首先查看返回的完整JSON文档,看看它说了什么Hanks Quentin!那为什么要在本地运行呢?当我插入Console.logimg_url代替return admin.firestore.collection'events.doc.createnewdoc时,控制台日志打印img_url。我不知道,这就是为什么你需要调试它!当它在10行之前抛出异常时,它如何记录它呢?好的,我已经记录了resultData.data,我得到了。。。我猜这意味着Instagram不允许从Firebase服务器请求,但允许从我的本地计算机请求?