You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google共享文件夹文件获取异常:仅得到“Getting Started”文件求助

Fix: Only Seeing "Getting Started" File When Accessing Shared Folder via Google Drive API

Hey there! Let's work through this frustrating issue you're facing—only pulling up the "Getting Started" file when trying to access a shared folder via the Google Drive API is totally fixable, so let's break it down step by step.

1. You're Using the Wrong API Method

It sounds like you tried using files().get, but that method is designed to fetch details of a single specific file—not list all content in a folder. To see every file in your shared folder, you need to use files().list with a filter query targeting the folder's contents.

2. Permissions Are Likely Missing

Double-check that your service account has been granted access to the shared folder:

  • Locate your service account's email in your JSON key file (look for the client_email field)
  • Ask the folder owner to share the folder with this email, granting at least "Viewer" permissions (or "Editor" if you need to download/write files)

3. Clean Up Your Authentication Setup

You've imported two different service account auth libraries (google.oauth2.service_account and oauth2client.service_account)—this can cause conflicts. Stick to the newer, maintained google-auth library for better reliability.

Corrected Code Example

Here's a cleaned-up script that will list all files in your shared folder and let you download them:

from google.oauth2 import service_account
from googleapiclient.discovery import build
import io
from googleapiclient.http import MediaIoBaseDownload

# Configuration - update these values
SERVICE_ACCOUNT_KEY_PATH = "path/to/your/service-account-key.json"
SHARED_FOLDER_ID = "your-shared-folder-id-here"
SCOPES = ["https://www.googleapis.com/auth/drive.readonly"]

# Authenticate with the Drive API
credentials = service_account.Credentials.from_service_account_file(
    SERVICE_ACCOUNT_KEY_PATH, scopes=SCOPES
)
drive_service = build("drive", "v3", credentials=credentials)

# List all non-trashed files in the shared folder
def list_shared_folder_contents(folder_id):
    results = drive_service.files().list(
        q=f"'{folder_id}' in parents and trashed=false",
        fields="files(id, name, mimeType)",
        supportsAllDrives=True  # Add this if the folder is in a Shared Drive/Team Drive
    ).execute()
    items = results.get("files", [])
    
    if not items:
        print("No files found in the shared folder.")
        return []
    print("Files in shared folder:")
    for item in items:
        print(f"- {item['name']} (ID: {item['id']})")
    return items

# Download a specific file from the folder
def download_file(file_id, file_name):
    request = drive_service.files().get_media(fileId=file_id)
    fh = io.FileIO(file_name, "wb")
    downloader = MediaIoBaseDownload(fh, request)
    done = False
    while done is False:
        status, done = downloader.next_chunk()
        print(f"Download progress: {int(status.progress() * 100)}%")
    print(f"File saved as {file_name}")

# Run the functions
folder_files = list_shared_folder_contents(SHARED_FOLDER_ID)
# Example: Download the first file in the list
if folder_files:
    download_file(folder_files[0]["id"], folder_files[0]["name"])

Key Notes:

  • The q parameter filters files where the shared folder is a parent, and excludes any trashed files
  • Add supportsAllDrives=True if your shared folder is part of a Google Workspace Shared Drive/Team Drive
  • Double-check your folder ID is correct (you can grab it from the folder's URL in Google Drive)

If you still don't see files after this, triple-check that the service account email was correctly added to the folder's sharing settings—typos here are a super common culprit!

内容的提问来源于stack exchange,提问作者Rod0n

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 08:33:40