我找到了这个文档 https://firebase.google.com/docs/storage/gcp-integration#apis
这是文档中的代码
# Import gcloud
from google.cloud import storage
# Enable Storage
client = storage.Client()
# Reference an existing bucket.
bucket = client.get_bucket('my-existing-bucket')
# Upload a local file to a new file to be created in your bucket.
zebraBlob = bucket.get_blob('zebra.jpg')
zebraBlob.upload_from_filename(filename='/photos/zoo/zebra.jpg')
# Download a file from your bucket.
giraffeBlob = bucket.get_blob('giraffe.jpg')
giraffeBlob.download_as_string()
内嵌 client = storage.Client()
说:
Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credential and re-run the application
下一步是我
from oauth2client.client import GoogleCredentials
GOOGLE_APPLICATION_CREDENTIALS = 'credentials.json'
credentials = GoogleCredentials.get_application_default()
说:
The Application Default Credentials are not available. They are available if running in Google Compute Engine
我的最后一个问题是如何在 Google Compute Engine 中进行身份验证。
请您参考如下方法:
问题解决了。
1.) 你需要安装https://cloud.google.com/sdk/
2.) 使用您的 gmail 登录 cloud sdk
3.) 选择你的 firebase 项目
4.) 将 gcloud auth application-default login 放入控制台
5.) 您可以在此处查看凭据
C:\Users\storks\AppData\Roaming\gcloud\application_default_credentials.json
6.) 有关详细信息,请参阅应用程序默认凭据的工作原理
https://developers.google.com/identity/protocols/application-default-credentials
