亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Google Drive SDK 版本 3 中的文件上傳

Google Drive SDK 版本 3 中的文件上傳

Go
喵喔喔 2021-12-07 10:11:10
我有一些基于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()

}


查看完整回答
反對 回復 2021-12-07
  • 1 回答
  • 0 關注
  • 204 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號