简体   繁体   English

Javascript 中的“缺少草稿消息”

[英]'Missing draft message' in Javascript

I am working on this issue from last 3 days.我最近 3 天一直在处理这个问题。 I dived through the stack overflow, but of no use.我潜入了堆栈溢出,但没有用。 There are the questions about "Missing draft message", but I am still getting this message.有关于“Missing draft message”的问题,但我仍然收到此消息。 I have tried all the ways they have said.他们说的方法我都试过了。 but I am still here.但我还在这里。 Here is my code这是我的代码

const str = "My Draft";
  const msgBody = btoa(str);
 
var token = localStorage.getItem("accessToken");

fetch(
  "https://gmail.googleapis.com/gmail/v1/users/me/drafts?key=[my api key] HTTP/1.1", 
  {
    
    method:"post",
    ContentType: 'application/json',
    Accept: 'application/json',
        headers: {
            
        "Authorization": `Bearer ${token}`,
        
    },
        message: {
            raw: msgBody
          }
  }
)
  .then((data) => data.json())
  .then((response) => console.log(response));

please add message in body https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#supplying_request_options请在正文中添加消息https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#supplying_request_options

const str = "My Draft";
const msgBody = btoa(str);
 
var token = localStorage.getItem("accessToken");

fetch(
  "https://gmail.googleapis.com/gmail/v1/users/me/drafts?key=[my api key] HTTP/1.1", 
  {
    method: 'POST',
    ContentType: 'application/json',
    Accept: 'application/json',
    headers: {
        "Authorization": `Bearer ${token}`,
    },
    body: JSON.stringify({ // Here changed 
        message: {
            raw: msgBody
        }
    }),
  }
)
  .then((data) => data.json())
  .then((response) => console.log(response));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM