准备工作
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
您必须先为项目启用 Cloud Vision API,然后才能使用它。
-
登录您的 Google Cloud 账号。如果您是 Google Cloud 新手,请创建一个账号来评估我们的产品在实际场景中的表现。新客户还可获享 $300 赠金,用于运行、测试和部署工作负载。
-
In the Google Cloud console, on the project selector page,
select or create a Google Cloud project.
Go to project selector
-
确保您的 Google Cloud 项目已启用结算功能。
-
启用 Vision API。
启用 API
-
Create a service account:
-
In the Google Cloud console, go to the Create service account page.
Go to Create service account
-
Select your project.
-
In the Service account name field, enter a name. The Google Cloud console fills
in the Service account ID field based on this name.
In the Service account description field, enter a description. For example,
Service account for quickstart
.
-
Click Create and continue.
-
Grant the Project > Owner role to the service account.
To grant the role, find the Select a role list, then select
Project > Owner.
-
Click Continue.
-
Click Done to finish creating the service account.
Do not close your browser window. You will use it in the next step.
-
Create a service account key:
-
In the Google Cloud console, click the email address for the service account that you
created.
-
Click Keys.
-
Click Add key, and then click Create new key.
-
Click Create. A JSON key file is downloaded to your computer.
-
Click Close.
-
将环境变量 GOOGLE_APPLICATION_CREDENTIALS
设置为包含凭据的 JSON 文件的路径。
此变量仅适用于当前的 shell 会话,因此,如果您打开新的会话,请重新设置该变量。
示例:Linux 或 macOS
export GOOGLE_APPLICATION_CREDENTIALS="KEY_PATH
"
将 KEY_PATH
替换为包含凭据的 JSON 文件的路径。
例如:
export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/service-account-file.json"
示例:Windows
对于 PowerShell:
$env:GOOGLE_APPLICATION_CREDENTIALS="KEY_PATH
"
将 KEY_PATH
替换为包含凭据的 JSON 文件的路径。
例如:
$env:GOOGLE_APPLICATION_CREDENTIALS="C:\Users\username\Downloads\service-account-file.json"
对于命令提示符:
set GOOGLE_APPLICATION_CREDENTIALS=KEY_PATH
将 KEY_PATH
替换为包含凭据的 JSON 文件的路径。
-
In the Google Cloud console, on the project selector page,
select or create a Google Cloud project.
Go to project selector
-
确保您的 Google Cloud 项目已启用结算功能。
-
启用 Vision API。
启用 API
-
Create a service account:
-
In the Google Cloud console, go to the Create service account page.
Go to Create service account
-
Select your project.
-
In the Service account name field, enter a name. The Google Cloud console fills
in the Service account ID field based on this name.
In the Service account description field, enter a description. For example,
Service account for quickstart
.
-
Click Create and continue.
-
Grant the Project > Owner role to the service account.
To grant the role, find the Select a role list, then select
Project > Owner.
-
Click Continue.
-
Click Done to finish creating the service account.
Do not close your browser window. You will use it in the next step.
-
Create a service account key:
-
In the Google Cloud console, click the email address for the service account that you
created.
-
Click Keys.
-
Click Add key, and then click Create new key.
-
Click Create. A JSON key file is downloaded to your computer.
-
Click Close.
-
将环境变量 GOOGLE_APPLICATION_CREDENTIALS
设置为包含凭据的 JSON 文件的路径。
此变量仅适用于当前的 shell 会话,因此,如果您打开新的会话,请重新设置该变量。
示例:Linux 或 macOS
export GOOGLE_APPLICATION_CREDENTIALS="KEY_PATH
"
将 KEY_PATH
替换为包含凭据的 JSON 文件的路径。
例如:
export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/service-account-file.json"
示例:Windows
对于 PowerShell:
$env:GOOGLE_APPLICATION_CREDENTIALS="KEY_PATH
"
将 KEY_PATH
替换为包含凭据的 JSON 文件的路径。
例如:
$env:GOOGLE_APPLICATION_CREDENTIALS="C:\Users\username\Downloads\service-account-file.json"
对于命令提示符:
set GOOGLE_APPLICATION_CREDENTIALS=KEY_PATH
将 KEY_PATH
替换为包含凭据的 JSON 文件的路径。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-07-26。
[{
"type": "thumb-down",
"id": "hardToUnderstand",
"label":"Hard to understand"
},{
"type": "thumb-down",
"id": "incorrectInformationOrSampleCode",
"label":"Incorrect information or sample code"
},{
"type": "thumb-down",
"id": "missingTheInformationSamplesINeed",
"label":"Missing the information/samples I need"
},{
"type": "thumb-down",
"id": "translationIssue",
"label":"翻译问题"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"其他"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"易于理解"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"解决了我的问题"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"其他"
}]