> ## 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.

# Tìm kiếm audio Instagram

> Tìm kiếm danh mục audio có bản quyền của Instagram để lấy một bản nhạc đính kèm vào Reel

export const InstagramAudioNotice = () => <Warning>
  <strong>Requires Instagram linked through Facebook Login.</strong> Instagram's Audio API is only available to accounts connected via <strong>Facebook Login</strong>, which needs a Facebook Page connected to the Instagram account. Accounts connected with <strong>Instagram Login</strong> (the Ayrshare default) cannot search, look up, or attach audio, and every audio request returns <code>code: 514</code>.
  <br /><br />
  This is a Meta restriction, not an Ayrshare one. Meta's documentation states the Audio API "is only available on the Instagram API with Facebook Login. It is not supported on the Instagram API with Instagram Login." No permission or plan upgrade changes it.
  <br /><br />
  <strong>Three things are required:</strong>
  <br />
  1. An Instagram <strong>Business</strong> or <strong>Creator</strong> account<br />
  2. A <strong>Facebook Page connected</strong> to that Instagram account<br />
  3. Instagram linked to Ayrshare with <strong>Instagram Login disabled</strong>, so the Facebook Login flow is used
  <br /><br />
  See the <a href="/docs/dashboard/connect-social-accounts/instagram#music-attach-eligibility-facebook-login-required">step-by-step setup guide</a>.
</Warning>;

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>;
};

export const HeaderAPI = ({noProfileKey, profileKeyRequired}) => <>
    <ParamField header="Authorization" type="string" required>
      <a href="/docs/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="/docs/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="/docs/apis/overview#profile-key-format">Profile Key</a> of a User Profile.
          <br />
          <br />
          Format: <code>Profile-Key: PROFILE_KEY</code>
        </ParamField>)}
  </>;

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

Tìm kiếm danh mục audio của Instagram theo từ khóa. Sử dụng `audioId` được trả về với [`instagramOptions.audioConfiguration`](/docs/apis/post/social-networks/instagram#adding-music-to-a-reel) để đính kèm bản nhạc khi bạn xuất bản một Reel.

<InstagramAudioNotice />

## Tham số Header

<HeaderAPI />

## Tham số Query

<ParamField query="query" type="string" required>
  Từ khóa để tìm kiếm, chẳng hạn như tên nghệ sĩ hoặc tên bản nhạc. Giá trị rỗng hoặc chỉ chứa
  khoảng trắng trả về `code: 101`.
</ParamField>

<ParamField query="audioType" type="string" default="music">
  Danh mục cần tìm kiếm. Hoặc `music` cho các bản nhạc thương mại có bản quyền hoặc `original_sound`
  cho audio lấy từ Reels của các creator khác. Bất kỳ giá trị nào khác trả về `code: 101`.
</ParamField>

<ParamField query="limit" type="integer">
  Số lượng bản nhạc tối đa được trả về, từ `1` đến `100`. Giá trị không phải số nguyên hoặc ngoài
  phạm vi trả về `code: 101`. Khi bỏ qua, giá trị mặc định của chính Instagram được áp dụng.
</ParamField>

## Trường Phản hồi

Instagram không trả về mọi trường cho mọi bản nhạc, vì vậy hãy coi tất cả các trường của bản nhạc ngoại trừ `audioId` là tùy chọn.

<ResponseField name="status" type="string">
  `success` khi tìm kiếm hoàn tất. Kết quả khớp rỗng trong danh mục vẫn là thành công.
</ResponseField>

<ResponseField name="query" type="string">
  Từ khóa đã được tìm kiếm, được trả lại nguyên trạng.
</ResponseField>

<ResponseField name="audio" type="array">
  Các bản nhạc khớp. Mảng rỗng có nghĩa là tìm kiếm đã chạy nhưng không khớp kết quả nào.

  <Expandable title="Các trường của bản nhạc">
    <ResponseField name="audioId" type="string">
      Id để truyền dưới dạng `audioConfiguration.audioId` khi xuất bản một Reel.
    </ResponseField>

    <ResponseField name="title" type="string">Tiêu đề bản nhạc.</ResponseField>
    <ResponseField name="displayArtist" type="string">Tên nghệ sĩ như Instagram hiển thị.</ResponseField>
    <ResponseField name="durationMs" type="integer">Độ dài bản nhạc tính bằng mili giây.</ResponseField>
    <ResponseField name="thumbnailUrl" type="string">URL thumbnail của ảnh bìa.</ResponseField>
    <ResponseField name="audioType" type="string">Hoặc `music` hoặc `original_sound`.</ResponseField>

    <ResponseField name="isAdsEligible" type="boolean">
      Liệu bản nhạc có thể được sử dụng trong quảng cáo hay không. Nhạc có bản quyền thường không
      khả dụng cho quảng cáo ngay cả khi nó khả dụng cho một Reel organic.
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseExample>
  ```json 200: Success theme={"system"}
  {
    "status": "success",
    "query": "summer",
    "audio": [
      {
        "audioId": "17901234567890123",
        "title": "Summer Nights",
        "displayArtist": "The Example Band",
        "durationMs": 32000,
        "thumbnailUrl": "https://scontent.example.com/cover.jpg",
        "audioType": "music",
        "isAdsEligible": true
      }
    ]
  }
  ```

  ```json 200: No matches theme={"system"}
  {
    "status": "success",
    "query": "asdfghjkl",
    "audio": []
  }
  ```

  ```json 400: Instagram Login account theme={"system"}
  {
    "status": "error",
    "code": 514,
    "action": "post",
    "message": "Adding music to a Reel requires an Instagram account connected via Facebook Login. This profile is connected with Instagram Login, which Meta does not permit for music attach, search, or lookup. Please relink Instagram using Facebook Login and grant the instagram_content_publish permission, then try again.",
    "platform": "instagram"
  }
  ```
</ResponseExample>

## Lỗi

| Mã | Ý nghĩa |
| - | - |
| 101 | `query` bị thiếu hoặc rỗng, `audioType` không được nhận diện, hoặc `limit` ngoài phạm vi 1 đến 100. |
| 156 | Instagram chưa được liên kết với profile này. |
| 161 | Ủy quyền của Instagram đã hết hạn hoặc bị thu hồi. Liên kết lại tài khoản. |
| 239 | Instagram đã từ chối yêu cầu vì một lý do ở cấp tài khoản, bao gồm cả bản nhạc không khả dụng. Trên tìm kiếm, trường hợp này báo 239 thay vì 517 mà endpoint tra cứu trả về. |
| 258 | Instagram trả về một phản hồi bị lỗi định dạng hoặc một thất bại chưa được ánh xạ. |
| 425 | Kết nối thiếu một quyền Instagram bắt buộc. Liên kết lại và cấp tất cả các quyền. |
| 435 | Đã đạt tới giới hạn tốc độ của Instagram. Chờ trước khi thử lại. |
| 514 | Instagram được liên kết bằng Instagram Login. Audio API yêu cầu Facebook Login. |

Các mã 514 đến 518 được mô tả trong [Lỗi audio Instagram Reels](/docs/errors/errors-ayrshare#instagram-reels-audio-errors); các mã còn lại nằm trong [tài liệu tham khảo lỗi Ayrshare](/docs/errors/errors-ayrshare).

## Các bước tiếp theo

<Card title="Đính kèm bản nhạc vào một Reel" icon="music" href="/docs/apis/post/social-networks/instagram#adding-music-to-a-reel" horizontal />

<Card title="Tra cứu một bản nhạc" icon="magnifying-glass" href="/docs/apis/media/get-instagram-audio" horizontal />


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.