如要快速開發,您可以使用 Google 助理 SDK 提供的註冊工具,快速註冊或更新裝置型號和執行個體。
如果不想使用這項工具,您可以透過 JSON 檔案和 REST API 手動註冊或更新裝置。您可以在任何電腦上執行這項操作請先取得存取權杖,然後跳至適當的部分。
取得存取權杖
確認授權工具是最新版本:
python -m pip install --upgrade google-auth-oauthlib[tool]
取得憑證以註冊新的裝置型號。參照您在前一個 步驟。
google-oauthlib-tool --scope https://www.googleapis.com/auth/assistant-sdk-prototype \ --headless --client-secrets /path/to/client_secret_client-id.json
終端機中應該會顯示網址:
Please visit this URL to authorize this application: https://...
複製網址並貼到瀏覽器 (可在開發機器或任何其他機器上執行)。核准之後,瀏覽器會顯示一組代碼,例如「4/XXXX」。複製以下程式碼並貼到終端機中:
Enter the authorization code:
如果授權成功,您會看到如下的 JSON 回應:
{ "scopes": ["https://www.googleapis.com/auth/assistant-sdk-prototype"], "token_uri": "https://accounts.google.com/o/oauth2/token", "token": "ya29.GlujBLa_kuXZ5GnGBPBe_A6NpczLcpOtglEC0wHVORnmEhHETzlSW", "client_id": "795595571889-6iesr9a3nkmnipbdfnqi6gehiklm2m28.apps.googleusercontent.com", "client_secret": "Un8_TNFnb55555auSAGasvAg", "refresh_token": "1/4ZMBhTR3bTYWVEMatYWLOxW755555hlQXZI5uC02F2U" }
而是看到
UNAUTHENTICATED
,代表輸入的代碼無效。 再試一次,謹慎複製及貼上完整程式碼。在 JSON 回應中找出
token
。將這個存取權杖 (不含雙引號) 複製到環境變數中:ACCESSTOKEN=access-token
裝置型號作業
定義及註冊裝置型號
建立檔案 (例如
device_model.json
) 說明裝置型號的特性。詳情請參閱裝置型號 JSON 參考資料。透過下列任一方法註冊裝置型號。請記得在以下網址中,取代與裝置型號相關聯的
project_id
。使用下列指令:
curl -s -X POST -H "Content-Type: application/json" \ -H "Authorization: Bearer $ACCESSTOKEN" -d @device_model.json \ https://embeddedassistant.googleapis.com/v1alpha2/projects/project_id/deviceModels/
請傳送含有下列屬性的 HTTPS 要求:
- 網址:https://embeddedassistant.googleapis.com/v1alpha2/projects/<project_id>/deviceModels/
- 方法:
POST
- 內文:
device_model.json
的內容 - 標頭:
Authorization: Bearer <access-token>
,其中 <access-token> 是包含存取權杖的字串
不論是哪一種方法,伺服器都應傳回您傳送的裝置型號 JSON 副本。如果伺服器上已有模型,您會收到
ALREADY_EXISTS
錯誤。
取得裝置型號
請透過下列任一方法取得裝置型號。請記得在以下網址中,使用與裝置型號相關聯的 project_id
和 device_model_id
。
使用下列指令:
curl -s -X GET -H "Content-Type: application/json" \ -H "Authorization: Bearer $ACCESSTOKEN" \ https://embeddedassistant.googleapis.com/v1alpha2/projects/project_id/deviceModels/device_model_id
請傳送含有下列屬性的 HTTPS 要求:
- 網址:https://embeddedassistant.googleapis.com/v1alpha2/projects/<project_id>/deviceModels/<device_model_id>
- 方法:
GET
- 內文:無
- 標頭:
Authorization: Bearer <access-token>
,其中 <access-token> 是包含存取權杖的字串
列出裝置型號
使用下列任一方法,列出特定專案的所有裝置型號。請記得在以下網址中,取代與裝置型號相關聯的 project_id
。
使用下列指令:
curl -s -X GET -H "Content-Type: application/json" \ -H "Authorization: Bearer $ACCESSTOKEN" \ https://embeddedassistant.googleapis.com/v1alpha2/projects/project_id/deviceModels/
請傳送含有下列屬性的 HTTPS 要求:
- 網址:https://embeddedassistant.googleapis.com/v1alpha2/projects/<project_id>/deviceModels/
- 方法:
GET
- 內文:無
- 標頭:
Authorization: Bearer <access-token>
,其中 <access-token> 是包含存取權杖的字串
更新裝置型號
使用下列任一方法更新裝置型號。請記得替換與裝置型號相關聯的 project_id
和 device_model_id
。
使用下列指令:
curl -s -X PUT -H "Content-Type: application/json" \ -H "Authorization: Bearer $ACCESSTOKEN" -d @device_model.json \ https://embeddedassistant.googleapis.com/v1alpha2/projects/project_id/deviceModels/device_model_id
請傳送含有下列屬性的 HTTPS 要求:
- 網址:https://embeddedassistant.googleapis.com/v1alpha2/projects/<project_id>/deviceModels/<device_model_id>
- 方法:
PUT
- 內文:
device_model.json
的內容 - 標頭:
Authorization: Bearer <access-token>
,其中 <access-token> 是包含存取權杖的字串
不論是哪一種方法,伺服器都應傳回您傳送的更新裝置型號 JSON 副本。
刪除裝置型號
您可以使用下列任一方法刪除裝置型號。請記得在以下網址中,使用與裝置型號相關聯的 project_id
和 device_model_id
。
使用下列指令:
curl -s -X DELETE -H "Content-Type: application/json" \ -H "Authorization: Bearer $ACCESSTOKEN" \ https://embeddedassistant.googleapis.com/v1alpha2/projects/project_id/deviceModels/device_model_id
請傳送含有下列屬性的 HTTPS 要求:
- 網址:https://embeddedassistant.googleapis.com/v1alpha2/projects/<project_id>/deviceModels/<device_model_id>
- 方法:
DELETE
- 內文:無
- 標頭:
Authorization: Bearer <access-token>
,其中 <access-token> 是包含存取權杖的字串
裝置執行個體作業
定義並註冊裝置執行個體
建立檔案 (例如
test_device.json
) 用於識別您的裝置。詳情請參閱裝置執行個體 JSON 參考資料。透過下列其中一種方法註冊裝置。請記得在以下網址中,取代與裝置型號相關聯的
project_id
。使用下列指令:
curl -s -X POST -H "Content-Type: application/json" \ -H "Authorization: Bearer $ACCESSTOKEN" -d @test_device.json \ https://embeddedassistant.googleapis.com/v1alpha2/projects/project_id/devices/
請傳送含有下列屬性的 HTTPS 要求:
- 網址:https://embeddedassistant.googleapis.com/v1alpha2/projects/<project_id>/devices/
- 方法:
POST
- 內文:
test_device.json
的內容 - 標頭:
Authorization: Bearer <access-token>
,其中 <access-token> 是包含存取權杖的字串
不論是哪一種方法,伺服器都應傳回您傳送的裝置執行個體 JSON 副本。如果伺服器上已有執行個體,您會收到
ALREADY_EXISTS
錯誤。
取得裝置執行個體
請透過下列任一方法取得裝置執行個體。請記得在下列網址中,取代與裝置型號和裝置 id
相關聯的 project_id
。
使用下列指令:
curl -s -X GET -H "Content-Type: application/json" \ -H "Authorization: Bearer $ACCESSTOKEN" \ https://embeddedassistant.googleapis.com/v1alpha2/projects/project_id/devices/id
請傳送含有下列屬性的 HTTPS 要求:
- 網址:https://embeddedassistant.googleapis.com/v1alpha2/projects/<project_id>/devices/<id>
- 方法:
GET
- 內文:無
- 標頭:
Authorization: Bearer <access-token>
,其中 <access-token> 是包含存取權杖的字串
列出裝置執行個體
請使用下列其中一種方法,列出特定專案的所有裝置執行個體。請記得在下列網址中,使用與裝置執行個體相關聯的 project_id
。
使用下列指令:
curl -s -X GET -H "Content-Type: application/json" \ -H "Authorization: Bearer $ACCESSTOKEN" \ https://embeddedassistant.googleapis.com/v1alpha2/projects/project_id/devices/
請傳送含有下列屬性的 HTTPS 要求:
- 網址:https://embeddedassistant.googleapis.com/v1alpha2/projects/<project_id>/devices/
- 方法:
GET
- 內文:無
- 標頭:
Authorization: Bearer <access-token>
,其中 <access-token> 是包含存取權杖的字串
刪除裝置執行個體
請透過下列任一方法刪除裝置執行個體。請記得在下列網址中,取代與裝置型號和裝置 id
相關聯的 project_id
。
使用下列指令:
curl -s -X DELETE -H "Content-Type: application/json" \ -H "Authorization: Bearer $ACCESSTOKEN" \ https://embeddedassistant.googleapis.com/v1alpha2/projects/project_id/devices/id
請傳送含有下列屬性的 HTTPS 要求:
- 網址:https://embeddedassistant.googleapis.com/v1alpha2/projects/<project_id>/devices/<id>
- 方法:
DELETE
- 內文:無
- 標頭:
Authorization: Bearer <access-token>
,其中 <access-token> 是包含存取權杖的字串