移动设备:缺少动作 [英] Mobiledevices: action missing

查看:63
本文介绍了移动设备:缺少动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行操作的POST,但是,当我发出请求时,我得到的代码400表示操作值丢失.

I am trying to perform a POST of the action, however, when I make the request I get code 400 speaking that the action value is missing.

我的代码:

function mobileAPIPOST() {

  var response = UrlFetchApp.fetch(
    "https://www.googleapis.com/admin/directory/v1/customer/my_customer/devices/mobile/fakexQ_fake0Z0dKFdSblfakeTnnfakel7IYwixfake4ddZfakeAIvnmu/action", {
      method: "POST",
      headers: {
        "Authorization": "Bearer " + ScriptApp.getOAuthToken(),
        "Content-Type": "application/json",
      },
      data: {
        "action": "block"
      },
      muteHttpExceptions: true
    });

}

我根据@TheMaster的响应更新了代码.

I updated the code following the response from @TheMaster.

我更新的代码:

function mobileAPIPOST() {

  var response = UrlFetchApp.fetch(
    "https://www.googleapis.com/admin/directory/v1/customer/my_customer/devices/mobile/fakexQ_fake0Z0dKFdSblfakeTnnfakel7IYwixfake4ddZfakeAIvnmu/action", {
      method: "POST",
      headers: {
        "Authorization": "Bearer " + ScriptApp.getOAuthToken(),
        "Content-Type": "application/json",
      },
      payload: {
        "action": "block"
      },
      muteHttpExceptions: true
    });

}

错误指出:

{
  "error": {
      "errors": [
       {
        "domain": "global",
        "reason": "parseError",
        "message": "Parse Error"
       }
      ],
      "code": 400,
      "message": "Parse Error"
     }
    }

推荐答案

UrlFetchApp没有data键参数.改为使用payload.

UrlFetchApp doesn't have a data key parameter. Use payload instead.

UrlFetchApp

UrlFetchApp.fetch(url,
    {
      method: "POST",
      headers: {
        "Authorization": "Bearer " + ScriptApp.getOAuthToken(),
      },
      contentType:  'application/json',
      payload: JSON.stringify({
        "action": "block"
      }),
      muteHttpExceptions: true
    });

这篇关于移动设备:缺少动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆