Stackdriver Logging API返回响应代码200,但响应为空

编程入门 行业动态 更新时间:2024-10-24 12:27:59
本文介绍了Stackdriver Logging API返回响应代码200,但响应为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试通过Stackdriver Logging API v2来获取stackdriver日志.我这样做是通过从Google Apps脚本项目发出POST请求来实现的,尤其是使用UrlFetchApp.问题是,它运行成功,但是日志中显示的响应为空.但是,当我使用apirequest.io,curl和Google API资源管理器发出相同的请求时,我得到了必要的响应.

I'm trying to fetch stackdriver logs via Stackdriver Logging API v2. I do this by making a POST request from google apps script project, in particular using UrlFetchApp. The thing is, it runs successfully, but the response shown in log is empty. However, when I made the same request using apirequest.io, curl and Google API explorer, I got the necessary response.

我进行了广泛搜索,但无济于事.尝试使用标头,网址,但一无所获.

I searched extensively, but to no avail. Tried experimenting with header, url, but nothing.

function exportLogs () { var options = { "method" : "post", "headers": {Authorization: 'Bearer ' + ScriptApp.getOAuthToken()}, "resourceNames": [ "projects/MyProject" ], "pageSize": 1, } var response = UrlFetchApp.fetch('logging.googleapis/v2/entries:list?key=MyApiKey', options) Logger.log(response) }

我想获取一些日志,但是我只得到{}

What I want to get is some logs, but I'm only getting {}

推荐答案

问题:

  • options对象中使用了不可接受的键.
  • Issue:

    • Unacceptable keys are used in options object.
      • payload是包括请求正文的唯一可接受的参数.
      • payload is the only acceptable parameter for including request body.
      function exportLogs() { var options = { method: "post", headers: { Authorization: 'Bearer ' + ScriptApp.getOAuthToken() }, //Include www.googleapis/auth/cloud-platform in scopes payload: JSON.stringify({ resourceNames: ['projects/[PROJECT_ID]'], pageSize: 1, }), }; var response = UrlFetchApp.fetch( 'logging.googleapis/v2/entries:list?key=MyApiKey', options ); Logger.log(response); }

      阅读:

      • Urlfetch#参数
      • 记录api#entriesList
      • 设置范围
      • To Read:

        • Urlfetch#params
        • Logging api#entriesList
        • Setting scopes

更多推荐

Stackdriver Logging API返回响应代码200,但响应为空

本文发布于:2023-10-30 22:33:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1544202.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:为空   代码   Logging   Stackdriver   API

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!