我有一些基于https://developers.google.com/drive/v2/reference/files/insert上的以下 Golang 示例的代碼。// InsertFile creates a new file in Drive from the given file and detailsfunc InsertFile(d *drive.Service, title string, description string,parentId string, mimeType string, filename string) (*drive.File, error) { . . . f := &drive.File{Title: title, Description: description, MimeType: mimeType} if parentId != "" { p := &drive.ParentReference{Id: parentId} f.Parents = []*drive.ParentReference{p} } r, err := d.Files.Insert(f).Media(m).Do() if err != nil { fmt.Printf("An error occurred: %v\n", err) return nil, err } return r, nil}當我切換到版本 3 時,會拋出以下錯誤。./main.go:125: unknown drive.File field 'Title' in struct literal./main.go:127: undefined: drive.ParentReference./main.go:128: undefined: drive.ParentReference./main.go:131: service.Files.Insert undefined (type *drive.FilesService has no field or method Insert)我知道 Title 應該在第一個錯誤中更改為 Name,但我不確定 SDK 版本 3 中是什么取代了 drive.ParentReference 或 service.Files.Insert,而且我找不到與鏈接等效的任何內容以上在 V3 文檔中。
1 回答

BIG陽
TA貢獻1859條經驗 獲得超6個贊
值得仔細閱讀此處的 Google API go 源代碼。您可以看到如何ParentReference 在 v2 API 代碼中存在但在 v3 中不存在。API 似乎從 v2 到 v3 發生了顯著變化。
從這些更改中推斷,以下是上傳文件的 v3 等效項的草圖:
import "google.golang.org/api/drive/v3"
func InsertFile(d *drive.Service, title string, description string, mimeType string, filename string) (*drive.File, error) {
f := &drive.File{Name: filename, Description: description, MimeType: mimeType}
return d.Files.Create(f).do()
}
- 1 回答
- 0 關注
- 204 瀏覽
添加回答
舉報
0/150
提交
取消