簡體   English   中英

將文件上傳到Google雲端硬盤

[英]Upload files to Google drive

我使用密鑰(P12)轉到Google雲端硬盤

我可以瀏覽文件夾,獲取有關文件的數據,獲取Google驅動器中的文件列表。 但是我無法將文件上傳到Google驅動器。

在TEAM上,所有設置都正確(是所有者)

為什么不給我保存文件的可能性?

示例代碼我成功獲取了文件夾列表:

def is_file_in_folder(service, folder_id, file_id):
  try:
    service.children().get(folderId=folder_id, childId=file_id).execute()
  except errors.HttpError, error:
    if error.resp.status == 404:
      return False
    else:
      print 'An error occurred: %s' % error
      raise error
  return True

我正在嘗試保存文件的示例代碼:

def insert_file(service, title, description, parent_id, mime_type, filename):
  media_body = MediaFileUpload(filename, mimetype=mime_type, resumable=True)
  body = {
    'title': title,
    'description': description,
    'mimeType': mime_type
  }
  if parent_id:
    body['parents'] = [{'id': parent_id}]

  try:
    file = service.files().insert(body=body, media_body=media_body).execute()

    return file
  except errors.HttpError, error:
    print 'An error occured: %s' % error
    return None

顯示錯誤-ERROR

我假設文件正在嘗試加載,但是由於某種原因(以及(resumable = True)),他阻止了他一次又一次的嘗試,直到那個時候。

我需要什么才能上傳文件?

嘗試使用該代碼在Google雲端硬盤中創建文件夾,但顯示錯誤(通過身份驗證的用戶無權訪問該文件)

那么如何獲得這些權利?

找到了問題。 它出現在“ Google雲端硬盤”界面中,並且在該文件夾上顯示為只讀,因此該用戶無法將文件上傳到該文件夾​​。 因此,並給出錯誤,僅允許讀取。

順便說一句,有人可以知道如何直接鏈接到文件。 此格式?: http : //google.com/my_file.mp3

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM