生成已签名的 HMAC 令牌
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
使用细分受众群重定向广告连播服务发出的每个细分受众群请求都必须包含
用于身份验证的 HMAC 签名的令牌(如果未使用
广告插播提前通知。
每次广告插播只能计算一次此令牌,并在所有直播中共享
会话。
收集令牌参数
从当前广告插播时间点收集以下信息,以填充
标记正文。
令牌参数
|
custom_asset_key
|
必需
|
来自 Google Ad Manager 的自定义直播素材资源键。
|
cust_params
|
可选
|
自定义定位参数。请参阅 cust_params 。
|
exp
|
必需
|
此令牌的到期时间戳(以秒为单位)。
|
network_code
|
必需
|
此广告资源网的 Ad Manager 360 广告资源网代码。
|
pod_id
|
必需
|
广告插播时间点的标识符。应为从 开始的整数
1 ,并针对每个广告插播时间点增加 1。
<ph type="x-smartling-placeholder"></ph>
在观看同一广告插播时间点的所有用户中,此值必须相同
当前事件
|
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 哈希值。通过
密钥是
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=
密钥
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
密钥
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
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):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"]],["最后更新时间 (UTC):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"]]