> ## Documentation Index
> Fetch the complete documentation index at: https://www.ayrshare.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# 设置 YouTube 水印

> 为你的 YouTube 频道设置水印

export const HeaderAPI = ({noProfileKey, profileKeyRequired}) => <>
    <ParamField header="Authorization" type="string" required>
      <a href="/apis/overview#authorization">API Key</a> of the Primary Profile.
      <br />
      <br />
      Format: <code>Authorization: Bearer API_KEY</code>
    </ParamField>
    {!noProfileKey && (profileKeyRequired ? <ParamField header="Profile-Key" type="string" required>
          <a href="/apis/overview#profile-key-format">Profile Key</a> of a User Profile.
          <br />
          <br />
          Format: <code>Profile-Key: PROFILE_KEY</code>
        </ParamField> : <ParamField header="Profile-Key" type="string">
          <a href="/apis/overview#profile-key-format">Profile Key</a> of a User Profile.
          <br />
          <br />
          Format: <code>Profile-Key: PROFILE_KEY</code>
        </ParamField>)}
  </>;

export const PlansAvailable = ({plans = [], maxPackRequired}) => {
  let displayPlans = plans;
  if (plans && plans.length === 1) {
    const lowerCasePlan = plans[0].toLowerCase();
    if (lowerCasePlan === "business") {
      displayPlans = ["Launch", "Business", "Enterprise"];
    } else if (lowerCasePlan === "premium") {
      displayPlans = ["Premium", "Launch", "Business", "Enterprise"];
    }
  }
  return <Note>
Available on {displayPlans.length === 1 ? "the " : ""}
{displayPlans.join(", ").replace(/\b\w/g, l => l.toUpperCase())}{" "}
{displayPlans.length > 1 ? "plans" : "plan"}.

{maxPackRequired && <span onClick={() => window.open('https://www.ayrshare.com/docs/additional/maxpack', '_self')} className="flex items-center mt-2 cursor-pointer">
 <span className="px-1.5 py-0.5 rounded text-sm" style={{
    backgroundColor: '#C264B6',
    color: 'white',
    fontSize: '12px'
  }}>
   Max Pack required
 </span>
</span>}
</Note>;
};

<PlansAvailable plans={["premium"]} maxPackRequired={false} />

在你的 YouTube 频道上设置一个水印图片,该水印将出现在所有视频上。可以配置水印在视频播放期间的显示时间。

<ul class="custom-bullets">
  <li>位置会自动设为右下角(YouTube API 默认值)</li>
  <li>设置水印时,所有时间参数 `timingType`、`offsetMs` 和 `durationMs` 均为必填</li>
  <li>水印将应用于该频道的所有视频(现有和未来的视频)</li>
  <li>水印图片必须符合 YouTube 的[水印媒体规范](/media-guidelines/youtube#watermark)</li>
  <li>你必须拥有管理该 YouTube 频道的相应权限</li>
</ul>

## Header 参数

<HeaderAPI noProfileKey={false} />

## Body 参数

<ParamField body="mediaUrls" type="array" required>
  包含水印图片 URL 的数组。仅使用第一个 URL。
</ParamField>

<ParamField body="timingType" type="string" required>
  视频播放期间显示水印的时机。

  可用的 timingType 取值:

  * `offsetFromStart` - 从视频开始后的某个特定时间开始显示水印
  * `offsetFromEnd` - 从视频结束前的某个特定时间开始显示水印
</ParamField>

<ParamField body="offsetMs" type="number" required>
  时间偏移量,以毫秒为单位。必须为正数。

  * 对于 `offsetFromStart`:视频开始后显示水印的时间
  * 对于 `offsetFromEnd`:视频结束前显示水印的时间
</ParamField>

<ParamField body="durationMs" type="number" required>
  显示水印的时长,以毫秒为单位。必须为正数。
</ParamField>

<RequestExample>
  ```bash cURL theme={"system"}
  curl \
  -H "Authorization: Bearer API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
    "mediaUrls": ["https://example.com/watermark.png"],
    "timingType": "offsetFromStart",
    "offsetMs": 15000,
    "durationMs": 30000
  }' \
  -X POST https://api.ayrshare.com/api/post/youTubeWatermark
  ```

  ```javascript JavaScript theme={"system"}
  const API_KEY = "API_KEY";

  fetch("https://api.ayrshare.com/api/post/youTubeWatermark", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "Authorization": `Bearer ${API_KEY}`
    },
    body: JSON.stringify({
      mediaUrls: ["https://example.com/watermark.png"],
      timingType: "offsetFromStart",
      offsetMs: 15000,
      durationMs: 30000
    }),
  })
    .then((res) => res.json())
    .then((json) => console.log(json))
    .catch(console.error);
  ```

  ```python Python theme={"system"}
  import requests

  payload = {
      'mediaUrls': ['https://example.com/watermark.png'],
      'timingType': 'offsetFromStart',
      'offsetMs': 15000,
      'durationMs': 30000
  }
  headers = {
      'Content-Type': 'application/json',
      'Authorization': 'Bearer API_KEY'
  }

  r = requests.post('https://api.ayrshare.com/api/post/youTubeWatermark',
      json=payload,
      headers=headers)

  print(r.json())
  ```

  ```php PHP theme={"system"}
  <?php

  $apiUrl = 'https://api.ayrshare.com/api/post/youTubeWatermark';
  $apiKey = 'API_KEY';  // Replace 'API_KEY' with your actual API key

  $headers = [
      'Content-Type: application/json',
      'Authorization: Bearer ' . $apiKey,
  ];

  $data = json_encode([
      'mediaUrls' => ['https://example.com/watermark.png'],
      'timingType' => 'offsetFromStart',
      'offsetMs' => 15000,
      'durationMs' => 30000
  ]);

  $curl = curl_init($apiUrl);
  curl_setopt_array($curl, [
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_POST => true,
      CURLOPT_HTTPHEADER => $headers,
      CURLOPT_POSTFIELDS => $data
  ]);

  $response = curl_exec($curl);

  if ($response === false) {
      echo 'Curl error: ' . curl_error($curl);
  } else {
      echo json_encode(json_decode($response), JSON_PRETTY_PRINT);
  }

  curl_close($curl);
  ```

  ```csharp C# theme={"system"}
  using System;
  using System.Net.Http;
  using System.Text;
  using System.Threading.Tasks;

  namespace SetYouTubeWatermark_csharp
  {
      class SetYouTubeWatermark
      {
          private static readonly HttpClient client = new HttpClient();

          static async Task Main(string[] args)
          {
              string API_KEY = "API_KEY";
              string url = "https://api.ayrshare.com/api/post/youTubeWatermark";

              // Set up request headers
              client.DefaultRequestHeaders.Add("Authorization", "Bearer " + API_KEY);

              // Prepare JSON content
              string json = @"{
                  ""mediaUrls"": [""https://example.com/watermark.png""],
                  ""timingType"": ""offsetFromStart"",
                  ""offsetMs"": 15000,
                  ""durationMs"": 30000
              }";
              var content = new StringContent(json, Encoding.UTF8, "application/json");

              try
              {
                  // Send POST request
                  HttpResponseMessage response = await client.PostAsync(url, content);
                  response.EnsureSuccessStatusCode();

                  // Read response
                  string responseBody = await response.Content.ReadAsStringAsync();
                  Console.WriteLine(responseBody);
              }
              catch (HttpRequestException e)
              {
                  Console.WriteLine($"Error: {e.Message}");
              }
          }
      }
  }
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={"system"}
  {
    "status": "success",
    "message": "Watermark set successfully",
    "mediaUrls": [
      "https://example.com/watermark.png"
    ],
    "timingType": "offsetFromStart",
    "offsetMs": 1000,
    "durationMs": 5000
  }
  ```

  ```json 400 - Invalid Image Dimensions theme={"system"}
  {
      "action": "post",
      "status": "error",
      "code": 140,
      "message": "The image aspect ratio must be between 1 and 1. Current image aspect ratio: 1085/723 (1.50). https://www.ayrshare.com/docs/media-guidelines/youtube "
  }
  ```

  ```json 400 - Unsupported Format theme={"system"}
  {
      "status": "error",
      "code": 307,
      "message": "Media type 'image/webp' is not supported. "
  }
  ```

  ```json 403 - Permission Error theme={"system"}
  {
    "status": "error",
    "code": 250,
    "message": "The watermark cannot be set for this channel. Please check that you have proper permissions and the channel is valid."
  }
  ```
</ResponseExample>
