產生已簽署的 HMAC 權杖
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
如果透過區隔重新導向廣告連播放送方式提出,每個區隔要求都必須包含
用於驗證的 HMAC 簽署憑證 (如未使用)
即將到來的廣告插播通知。
每個廣告插播時間點可以計算這個權杖一次,並在所有串流中共用
工作階段。
收集權杖參數
從目前的廣告插播收集下列資訊來填入
符記主體
權杖參數
|
custom_asset_key
|
必要
|
Google Ad Manager 提供的自訂直播素材資源鍵。
|
cust_params
|
選用
|
自訂指定參數。詳情請參閱 cust_params 。
|
exp
|
必要
|
這個權杖的到期時間戳記 (以秒為單位)。
|
network_code
|
必要
|
這個聯播網的 Ad Manager 360 聯播網代碼。
|
pod_id
|
必要
|
廣告插播的 ID。須為整數,開頭應為
1 ,並針對每個廣告插播增加 1 次。
在所有查看相同廣告插播時間點的所有使用者,這個值都必須相同
目前的事件。
|
pd
|
必填 (啟用未指定時間長度廣告時段的事件除外)。
|
廣告插播的時間長度 (以毫秒為單位)。上述指的是
ad_pod_duration 。
|
scte35
|
選用
|
採用 Base64 編碼的 SCTE-35 信號。客戶必須負責確保
訊號是否正確無誤如果不正確,系統會將訊息傳送至
回應中的 X-Ad-Manager-Dai-Warning HTTP 標頭和
但信號仍會傳播以建立廣告插播時間點詳情請參閱支援
廣告標記,進一步瞭解 DAI 如何使用 SCTE-35 信號。
|
建立符記字串
按字母順序列出每個參數,格式為 name=value
,
名稱值組合,並以波浪號 (~
) 字元分隔。
沒有值的選用參數可以放在沒有值的選用參數中,但保留空白字串
或完全移除
custom_asset_key={custom_asset_key}~exp={expiration}~network_code={network_code}~pd={pod_duration}~pod_id={ad_pod_index}~scte35={scte35_message}
產生 HMAC 簽章
HMAC 簽章是權杖字串的 SHA-256 雜湊,採用 HEX 格式。
密鑰則是
HMAC 驗證金鑰
與 Google Ad Manager 中的直播活動建立關聯
簽署權杖字串
產生憑證後,請將 HMAC 簽名附加至以下字串中的憑證字串:
格式
~hmac={HMAC signature}
網址編碼權杖字串
這個權杖是以網址參數的形式傳遞,因此必須採用網址編碼以確保安全。
範例 1
以下範例將未使用的選用參數設為空白
字串。
權杖字串
custom_asset_key=iYdOkYZdQ1KFULXSN0Gi7g~cust_params=~exp=1489680000~network_code=6062~pd=180000~pod_id=5~scte35=
Secret 金鑰
A7490591290583E4B93189DEE7E287C299FC686872ABC7ADC9F9F536443505F
HMAC 簽章
86d7e5f8c96fe4c83141d764df376ae14a0e2066f2e6b2ccfb9e1e2d3c869a88
已簽署的權杖
custom_asset_key=iYdOkYZdQ1KFULXSN0Gi7g~cust_params=~exp=1489680000~network_code=6062~pd=180000~pod_id=5~scte35=~hmac=86d7e5f8c96fe4c83141d764df376ae14a0e2066f2e6b2ccfb9e1e2d3c869a88
網址編碼簽署權杖:
custom_asset_key%3DiYdOkYZdQ1KFULXSN0Gi7g~cust_params%3D~exp%3D1489680000~network_code%3D6062~pd%3D180000~pod_id%3D5~scte35%3D~hmac%3D86d7e5f8c96fe4c83141d764df376ae14a0e2066f2e6b2ccfb9e1e2d3c869a88
範例 2
在以下範例中,系統會完全省略未填入的選用變數。
權杖字串
custom_asset_key=iYdOkYZdQ1KFULXSN0Gi7g3~exp=1489680000~network_code=6062~pd=180000~pod_id=5
Secret 金鑰
A7490591290583E4B93189DEE7E287C299FC686872ABC7ADC9F9F536443505F
HMAC 簽章
6a8c44c72e4718ff63ad2284edf2a8b9e319600b430349d31195c99b505858c9
已簽署的權杖
custom_asset_key=iYdOkYZdQ1KFULXSN0Gi7g~exp=1489680000~network_code=6062~pd=180000~pod_id=5~hmac=6a8c44c72e4718ff63ad2284edf2a8b9e319600b430349d31195c99b505858c9
網址編碼的已簽署權杖
custom_asset_key%3DiYdOkYZdQ1KFULXSN0Gi7g~exp%3D1489680000~network_code%3D6062~pd%3D180000~pod_id%3D5~hmac%3D6a8c44c72e4718ff63ad2284edf2a8b9e319600b430349d31195c99b505858c9
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-21 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-21 (世界標準時間)。"],[[["\u003cp\u003eEach segment request using segment redirect pod serving requires an HMAC-signed token for authentication unless using early ad break notifications.\u003c/p\u003e\n"],["\u003cp\u003eThe token includes parameters like custom asset key, network code, pod ID, and duration, gathered from the ad break.\u003c/p\u003e\n"],["\u003cp\u003eAn HMAC signature is generated using a SHA-256 hash of the token string and a secret key from Google Ad Manager.\u003c/p\u003e\n"],["\u003cp\u003eThis signature is appended to the token string, which is then URL-encoded before being included in the segment request.\u003c/p\u003e\n"]]],[],null,["# Generate a signed HMAC token\n\nEach segment request made using segment redirect pod serving must include a\nHMAC-signed token for authentication, if not using\n[early ad break notifications](/ad-manager/video/Early.ad.break.notification).\n\nThis token can be calculated once per ad break and shared across all stream\nsessions.\n\nGather token parameters\n-----------------------\n\nGather the following information from the current ad break, to populate the\ntoken body.\n\n| Token Parameters |||\n|--------------------|------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `custom_asset_key` | Required | The custom livestream asset key, from Google Ad Manager. |\n| `cust_params` | Optional | Custom targeting parameters. See [cust_params](//support.google.com/admanager/answer/1080597). |\n| `exp` | Required | Expiration timestamp for this token in seconds. |\n| `network_code` | Required | The Ad Manager 360 network code for this network. |\n| `pod_id` | Required | Identifier for the ad break. Should be an integer starting at `1` and increasing by one for each ad break. **This value must be the same across all users viewing the same ad break in the current event.** |\n| `pd` | Required, except for events with durationless ad breaks enabled. | The duration in milliseconds of the ad break. Referred to above as `ad_pod_duration`. |\n| `scte35` | Optional | Base64-encoded SCTE-35 signal. It's the client's responsibility to ensure that the signal is correct. If incorrect, a message is sent to the `X-Ad-Manager-Dai-Warning` HTTP header in the response and the signal is still propagated to create an ad break. See the [supported ad markers](//support.google.com/admanager/answer/7245661#supported-ad-markers) for more information on how DAI uses the SCTE-35 signal. |\n\nCreate token string\n-------------------\n\nlist each parameter in alphabetical order, in the format `name=value`, with each\nname-value pair separated by a tilde (`~`) character.\n\nOptional parameters without a value can be left in-place with an empty string\nfor the value, or removed entirely.\n\n### token string format\n\n custom_asset_key={custom_asset_key}~exp={expiration}~network_code={network_code}~pd={pod_duration}~pod_id={ad_pod_index}~scte35={scte35_message}\n\nGenerate HMAC signature\n-----------------------\n\nThe HMAC signature is a SHA-256 hash of the token string in HEX format. The\nsecret key is the\n[HMAC authentication key](//support.google.com/admanager/answer/6381445)\nassociated with your livestream event in Google Ad Manager.\n\nSign token string\n-----------------\n\nOnce generated, append the HMAC signature to the token string in the following\nformat \n\n ~hmac={HMAC signature}\n\nURL-encode token string\n-----------------------\n\nThis token is passed as a URL parameter, so it must be URL-encoded for safety.\n\n### Example 1\n\nHere's an example where unused optional parameters are included as empty\nstrings.\n\n#### Token string\n\n custom_asset_key=iYdOkYZdQ1KFULXSN0Gi7g~cust_params=~exp=1489680000~network_code=6062~pd=180000~pod_id=5~scte35=\n\n#### Secret key\n\n A7490591290583E4B93189DEE7E287C299FC686872ABC7ADC9F9F536443505F\n\n#### HMAC signature\n\n 86d7e5f8c96fe4c83141d764df376ae14a0e2066f2e6b2ccfb9e1e2d3c869a88\n\n#### Signed token\n\n custom_asset_key=iYdOkYZdQ1KFULXSN0Gi7g~cust_params=~exp=1489680000~network_code=6062~pd=180000~pod_id=5~scte35=~hmac=86d7e5f8c96fe4c83141d764df376ae14a0e2066f2e6b2ccfb9e1e2d3c869a88\n\n#### URL-encoded signed token:\n\n custom_asset_key%3DiYdOkYZdQ1KFULXSN0Gi7g~cust_params%3D~exp%3D1489680000~network_code%3D6062~pd%3D180000~pod_id%3D5~scte35%3D~hmac%3D86d7e5f8c96fe4c83141d764df376ae14a0e2066f2e6b2ccfb9e1e2d3c869a88\n\n### Example 2\n\nHere's an example where the unpopulated optional variables are omitted entirely.\n\n#### Token string\n\n custom_asset_key=iYdOkYZdQ1KFULXSN0Gi7g3~exp=1489680000~network_code=6062~pd=180000~pod_id=5\n\n##### Secret key\n\n A7490591290583E4B93189DEE7E287C299FC686872ABC7ADC9F9F536443505F\n\n##### HMAC signature\n\n 6a8c44c72e4718ff63ad2284edf2a8b9e319600b430349d31195c99b505858c9\n\n#### Signed token\n\n custom_asset_key=iYdOkYZdQ1KFULXSN0Gi7g~exp=1489680000~network_code=6062~pd=180000~pod_id=5~hmac=6a8c44c72e4718ff63ad2284edf2a8b9e319600b430349d31195c99b505858c9\n\n#### URL-encoded signed token\n\n custom_asset_key%3DiYdOkYZdQ1KFULXSN0Gi7g~exp%3D1489680000~network_code%3D6062~pd%3D180000~pod_id%3D5~hmac%3D6a8c44c72e4718ff63ad2284edf2a8b9e319600b430349d31195c99b505858c9"]]