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

# Sở thích

> Lấy các sở thích quảng cáo Facebook

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="/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>)}
  </>;

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

Tìm kiếm các tùy chọn nhắm mục tiêu theo sở thích khả dụng của quảng cáo Facebook theo từ khóa.
Sử dụng endpoint này để tra cứu ID sở thích cho endpoint [Boost Post](/apis/ads/facebook/boost-post).

Endpoint này giúp bạn khám phá các tùy chọn nhắm mục tiêu dựa trên sở thích cho quảng cáo Facebook, kèm theo ước tính quy mô đối tượng.

<ul className="custom-bullets">
  <li>ID sở thích có thể được sử dụng trong mảng `interests` khi boost bài đăng.</li>
  <li>Kết quả được cache trong 10 phút.</li>
  <li>Sử dụng các từ khóa tìm kiếm cụ thể, liên quan để có kết quả tốt nhất.</li>
  <li>Facebook có thể trả về các kết quả khác nhau dựa trên ngành và khu vực của tài khoản quảng cáo của bạn.</li>

  <li>
    Các trường `audienceSizeLowerBound` và `audienceSizeUpperBound` trong phản hồi JSON cung cấp
    khoảng ước tính quy mô đối tượng cho sở thích và hữu ích cho việc nhắm mục tiêu.
  </li>
</ul>

## Tham số Header

<HeaderAPI />

## Tham số Query

<ParamField query="search" type="string" required>
  Truy vấn tìm kiếm để lấy các sở thích quảng cáo Facebook.

  Đừng quên escape (mã hóa URL) truy vấn tìm kiếm, ví dụ `Rhythm%20and%20blues%20music`.
</ParamField>

<ParamField query="limit" type="number" default={100}>
  Giới hạn số lượng sở thích quảng cáo được trả về.
</ParamField>

<RequestExample>
  ```bash cURL theme={"system"}
  curl \
  -H "Authorization: Bearer API_KEY" \
  -X GET https://api.ayrshare.com/api/ads/facebook/interests?search=Rhythm%20and%20blues%20music
  ```

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

  fetch("https://api.ayrshare.com/api/ads/facebook/interests?search=Rhythm%20and%20blues%20music", {
        method: "GET",
        headers: {
          "Authorization": `Bearer ${API_KEY}`
        }
      })
        .then((res) => res.json())
        .then((json) => console.log(json))
        .catch(console.error);
  ```

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

  headers = {'Authorization': 'Bearer API_KEY'}

  r = requests.get('https://api.ayrshare.com/api/ads/facebook/interests?search=Rhythm%20and%20blues%20music', headers=headers)

  print(r.json())
  ```

  ```php PHP theme={"system"}
  <?php
  $curl = curl_init();

  curl_setopt_array($curl, [
    CURLOPT_URL => "https://api.ayrshare.com/api/ads/facebook/interests?search=Rhythm%20and%20blues%20music",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
      "Authorization: Bearer API_KEY"
    ],
  ]);

  $response = curl_exec($curl);
  curl_close($curl);

  echo $response;
  ?>
  ```

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

  class Program
  {
      static async Task Main()
      {
          var client = new HttpClient();
          client.DefaultRequestHeaders.Add("Authorization", "Bearer API_KEY");

          var response = await client.GetAsync("https://api.ayrshare.com/api/ads/facebook/interests?search=Rhythm%20and%20blues%20music");
          var content = await response.Content.ReadAsStringAsync();

          Console.WriteLine(content);
      }
  }
  ```

  ```go Go theme={"system"}
  package main

  import (
      "fmt"
      "io/ioutil"
      "net/http"
  )

  func main() {
      client := &http.Client{}
      req, _ := http.NewRequest("GET", "https://api.ayrshare.com/api/ads/facebook/interests?search=Rhythm%20and%20blues%20music", nil)
      req.Header.Add("Authorization", "Bearer API_KEY")

      resp, _ := client.Do(req)
      body, _ := ioutil.ReadAll(resp.Body)

      fmt.Println(string(body))
  }
  ```

  ```java Java theme={"system"}
  import java.net.URI;
  import java.net.http.HttpClient;
  import java.net.http.HttpRequest;
  import java.net.http.HttpResponse;

  public class GetAdInterests {
      public static void main(String[] args) throws Exception {
          HttpClient client = HttpClient.newHttpClient();
          HttpRequest request = HttpRequest.newBuilder()
                  .uri(URI.create("https://api.ayrshare.com/api/ads/facebook/interests?search=Rhythm%20and%20blues%20music"))
                  .header("Authorization", "Bearer API_KEY")
                  .GET()
                  .build();

          HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
          System.out.println(response.body());
      }
  }
  ```

  ```ruby Ruby theme={"system"}
  require 'net/http'
  require 'json'

  uri = URI('https://api.ayrshare.com/api/ads/facebook/interests?search=Rhythm%20and%20blues%20music')
  req = Net::HTTP::Get.new(uri)
  req['Authorization'] = 'Bearer API_KEY'

  res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http|
    http.request(req)
  }

  puts res.body
  ```
</RequestExample>

<ResponseExample>
  ```json 200: Thành công theme={"system"}
  {
      "status": "success",
      "interests": [
          {
              "id": "6003195554098",
              "name": "Rhythm and blues music",
              "topic": "News and entertainment",
              "audienceSizeLowerBound": 669180255,
              "audienceSizeUpperBound": 786955980
          },
          {
              "id": "6003470511564",
              "name": "Do it yourself (DIY)",
              "topic": "Hobbies and activities",
              "audienceSizeLowerBound": 418387661,  // Lower bound of audience size
              "audienceSizeUpperBound": 492023890  // Upper bound of audience size
          },
          {
              "id": "6002926036121",
              "name": "Italy",
              "topic": "Travel, places and events",
              "audienceSizeLowerBound": 279313350,  // Lower bound of audience size
              "audienceSizeUpperBound": 328472500  // Upper bound of audience size
          }
      ],
      "count": 3,
      "lastUpdated": "2025-03-27T01:01:38.547Z",
      "nextUpdate": "2025-03-27T01:12:38.547Z"
  }
  ```

  ```json 400: Lỗi sở thích quảng cáo theme={"system"}
  {
    "action": "get ad interests",
    "status": "error",
    "code": 368,
    "message": "Error getting ad interests. Please try again or contact us if the issue persists."
  }
  ```
</ResponseExample>
