且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Salesforce Apex Google Drive API 正在使用 mimeType“application/json"创建新文件

更新时间:2022-12-03 19:56:06

您使用了错误的端点.您发布到 content 端点,而不是 file 端点.

You've used the wrong endpoint. Instead of the file endpoint, you're posting to the content endpoint.

所以

req.setEndpoint('https://www.googleapis.com/upload/驱动器/v2/文件');

req.setEndpoint('https://www.googleapis.com/upload/drive/v2/files');

应该是(对于 v2 API)

should be (for the v2 API)

req.setEndpoint('https://www.googleapis.com/drive/v2/文件');

req.setEndpoint('https://www.googleapis.com/drive/v2/files');

或(对于 v3 API)

or (for the v3 API)

req.setEndpoint('https://www.googleapis.com/drive/v3/文件');

req.setEndpoint('https://www.googleapis.com/drive/v3/files');

如果你使用 v3(你可能应该这样做),你的 json 应该因此改变

If you use v3 (which you probably should), your json should change thus

String jsonData = '{"name":"NewFolder", "mimeType":"application/vnd.google-apps.folder"}';

String jsonData = '{"name":"NewFolder", "mimeType":"application/vnd.google-apps.folder"}';