串流要求會為直播活動註冊工作階段。 詳情請參閱「提出串流要求」。
本頁說明如何使用 HMAC 權杖驗證串流要求。
事前準備
請先完成下列事項,再繼續操作:
- 完成必要條件。
- 在 Google Ad Manager 帳戶中,為直播活動啟用「串流建立驗證金鑰」。如果您使用權杖驗證,則必須提供金鑰。
產生 HMAC 權杖
如要產生權杖,請按照下列步驟操作:
- 收集直播的資產金鑰和到期時間。詳情請參閱「啟用驗證,以建立 DAI 串流工作階段」。
依字母順序排序下列參數,並以半形波浪號
~字元分隔參數:event=ASSET_KEY~exp=EXPIRATION更改下列內容:
ASSET_KEY:必要。直播活動的資產金鑰。EXPIRATION:必要。權杖的到期時間戳記,以 Unix 紀元時間表示。
使用 DAI 驗證金鑰計算權杖字串的 SHA-256 雜湊。
以十六進位格式輸出雜湊。
如要簽署權杖字串,請在先前收集的參數結尾附加簽章:
event=...~hmac=HMAC_SIGNATURE使用 DAI 驗證金鑰雜湊處理權杖字串,然後以產生的簽章取代
HMAC_SIGNATURE。如要安全地傳遞已簽署的權杖字串,請對已簽署的權杖字串套用網址編碼。
以下範例會簽署及編碼在 60 秒內過期的權杖字串:
# Add 60 seconds to the current time
future_epoch=$((EPOCHSECONDS + 60))
echo "Current: $EPOCHSECONDS"
echo "Future: $future_epoch"
# Current: 1767389133
# Future: 1767389193
# Sample DAI stream authentication key
key="DE0E9..."
# Sort parameters in the token string
token="event=YRB0Bl0oQRCb5J-maPpJUQ~exp=1767389193"
# Generate the token's signature.
echo -n $token | openssl dgst -sha256 -mac HMAC -macopt key:$key
# SHA2-256(stdin)= 9935a013957e5ce893a7ee444d3d452fd0de7d273ff8b65471ddd4619b80d248
# Sign the token: event=YRB0Bl0oQRCb5J-maPpJUQ~exp=1767389193~hmac=9935a013957e5ce893a7ee444d3d452fd0de7d273ff8b65471ddd4619b80d248
# Encode the token: event%3DYRB0Bl0oQRCb5J%2DmaPpJUQ%7Eexp%3D1767389193%7Ehmac%3D9935a013957e5ce893a7ee444d3d452fd0de7d273ff8b65471ddd4619b80d248
使用 HMAC 權杖要求直播工作階段
如要使用 HMAC 權杖驗證串流建立要求,請執行下列其中一項操作:
Authorization 要求標頭
curl "https://dai.google.com/linear/v1/hls/event/YRB0Bl0oQRCb5J-maPpJUQ/stream" \
-X POST \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Authorization: DCLKDAI token=event%3DYRB0Bl0oQRCb5J%2DmaPpJUQ%7Eexp%3D1767389193%7Ehmac%3D9935a013957e5ce893a7ee444d3d452fd0de7d273ff8b65471ddd4619b80d248"
查詢字串參數
curl "https://dai.google.com/linear/v1/hls/event/YRB0Bl0oQRCb5J-maPpJUQ/stream?auth-token=event%3DYRB0Bl0oQRCb5J%2DmaPpJUQ%7Eexp%3D1767389193%7Ehmac%3D9935a013957e5ce893a7ee444d3d452fd0de7d273ff8b65471ddd4619b80d248" \
-X POST \
-H "Content-Type: application/x-www-form-urlencoded"
表單資料欄位
curl "https://dai.google.com/linear/v1/hls/event/YRB0Bl0oQRCb5J-maPpJUQ/stream" \
-X POST \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "auth-token=event%3DYRB0Bl0oQRCb5J%2DmaPpJUQ%7Eexp%3D1767389193%7Ehmac%3D9935a013957e5ce893a7ee444d3d452fd0de7d273ff8b65471ddd4619b80d248"
如果成功,您會看到下列 JSON 回應:
{
"hls_master_playlist": "https://dai.google.com/linear/hls/pa/event/YRB0Bl0oQRCb5J-maPpJUQ/stream/e91f907e-6a0a-4795-8c96-c8e36e89cbf6:DLS/master.m3u8",
"media_verification_url": "https://dai.google.com/view/p/service/linear/stream/e91f907e-6a0a-4795-8c96-c8e36e89cbf6:DLS/loc/DLS/network/21775744923/event/YRB0Bl0oQRCb5J-maPpJUQ/media/",
"metadata_url": "https://dai.google.com/linear/v1/pa/event/YRB0Bl0oQRCb5J-maPpJUQ/stream/e91f907e-6a0a-4795-8c96-c8e36e89cbf6:DLS/metadata",
"polling_frequency": 10,
"session_update_url": "https://dai.google.com/linear/v1/pa/event/YRB0Bl0oQRCb5J-maPpJUQ/stream/e91f907e-6a0a-4795-8c96-c8e36e89cbf6:DLS/session",
"stream_id": "e91f907e-6a0a-4795-8c96-c8e36e89cbf6:DLS",
"stream_manifest": "https://dai.google.com/linear/hls/pa/event/YRB0Bl0oQRCb5J-maPpJUQ/stream/e91f907e-6a0a-4795-8c96-c8e36e89cbf6:DLS/master.m3u8"
}
如要瞭解回應結構和狀態碼,請參閱「方法:串流」。 如果驗證失敗,系統會顯示下列錯誤訊息:
<!DOCTYPE html>
<html lang=en>
<meta charset=utf-8>
<meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
<title>Error 401 (Unauthorized)!!1</title>
...
<a href=//www.google.com/><span id=logo aria-label=Google></span></a>
<p><b>401.</b> <ins>That’s an error.</ins>
<p><ins>That’s all we know.</ins>