> ## Documentation Index
> Fetch the complete documentation index at: https://generaltranslation.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Démarrage rapide

> Rechercher des Spaces par mot-clé

export const Button = ({href, children}) => {
  return <div className="not-prose group">
    <a href={href}>
      <button className="flex items-center space-x-2.5 py-1 px-4 bg-primary-dark dark:bg-white text-white dark:text-gray-950 rounded-full group-hover:opacity-[0.9] font-medium">
        <span>
          {children}
        </span>
        <svg width="3" height="24" viewBox="0 -9 3 24" class="h-6 rotate-0 overflow-visible"><path d="M0 0L3 3L0 6" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"></path></svg>
      </button>
    </a>
  </div>;
};

Ce guide vous explique comment rechercher des Spaces par mot-clé.

<Note>
  **Prérequis**

  Avant de commencer, vous aurez besoin de :

  * D’un [compte développeur](https://developer.x.com/en/portal/petition/essential/basic-info) avec une App approuvée
  * Du Jeton Bearer de votre App
</Note>

***

<div id="search-for-spaces">
  ## Rechercher des Spaces
</div>

Recherchez des Spaces qui correspondent à un mot-clé :

<CodeGroup dropdown>
  ```bash cURL theme={null}
  curl "https://api.x.com/2/spaces/search?\
  query=AI&\
  space.fields=title,host_ids,participant_count,state&\
  state=live" \
    -H "Authorization: Bearer $BEARER_TOKEN"
  ```

  ```python Python SDK theme={null}
  from xdk import Client

  client = Client(bearer_token="YOUR_BEARER_TOKEN")

  # Rechercher des Spaces
  response = client.spaces.search(
      query="AI",
      space_fields=["title", "host_ids", "participant_count", "state"],
      state="live"
  )

  for space in response.data:
      print(f"{space.title} - {space.participant_count} participants")
  ```

  ```javascript JavaScript SDK theme={null}
  import { Client } from "@xdevplatform/xdk";

  const client = new Client({ bearerToken: "YOUR_BEARER_TOKEN" });

  // Rechercher des Spaces
  const response = await client.spaces.search({
    query: "AI",
    spaceFields: ["title", "host_ids", "participant_count", "state"],
    state: "live",
  });

  response.data?.forEach((space) => {
    console.log(`${space.title} - ${space.participant_count} participants`);
  });
  ```
</CodeGroup>

<div id="response">
  ### Réponse
</div>

```json theme={null}
{
  "data": [
    {
      "id": "1DXxyRYNejbKM",
      "state": "live",
      "title": "Discussing AI and the Future",
      "host_ids": ["2244994945"],
      "participant_count": 245
    },
    {
      "id": "1YqJDqWYNQDGW",
      "state": "live",
      "title": "AI in Healthcare",
      "host_ids": ["783214"],
      "participant_count": 89
    }
  ],
  "meta": {
    "result_count": 2
  }
}
```

***

<div id="filter-by-state">
  ## Filtrer par statut
</div>

Rechercher uniquement les Spaces en direct ou programmés :

<div id="live-spaces-only">
  ### Spaces en direct uniquement
</div>

<CodeGroup dropdown>
  ```bash cURL theme={null}
  curl "https://api.x.com/2/spaces/search?query=tech&state=live" \
    -H "Authorization: Bearer $BEARER_TOKEN"
  ```

  ```python Python SDK theme={null}
  from xdk import Client

  client = Client(bearer_token="YOUR_BEARER_TOKEN")

  # Rechercher uniquement des Spaces en direct
  response = client.spaces.search(query="tech", state="live")

  for space in response.data:
      print(f"LIVE: {space.title}")
  ```

  ```javascript JavaScript SDK theme={null}
  import { Client } from "@xdevplatform/xdk";

  const client = new Client({ bearerToken: "YOUR_BEARER_TOKEN" });

  // Rechercher uniquement des Spaces en direct
  const response = await client.spaces.search({
    query: "tech",
    state: "live",
  });

  response.data?.forEach((space) => {
    console.log(`LIVE: ${space.title}`);
  });
  ```
</CodeGroup>

<div id="scheduled-spaces-only">
  ### Spaces programmées uniquement
</div>

<CodeGroup dropdown>
  ```bash cURL theme={null}
  curl "https://api.x.com/2/spaces/search?query=tech&state=scheduled" \
    -H "Authorization: Bearer $BEARER_TOKEN"
  ```

  ```python Python SDK theme={null}
  from xdk import Client

  client = Client(bearer_token="YOUR_BEARER_TOKEN")

  # Rechercher uniquement les Spaces programmées
  response = client.spaces.search(query="tech", state="scheduled")

  for space in response.data:
      print(f"SCHEDULED: {space.title}")
  ```

  ```javascript JavaScript SDK theme={null}
  import { Client } from "@xdevplatform/xdk";

  const client = new Client({ bearerToken: "YOUR_BEARER_TOKEN" });

  // Rechercher uniquement les Spaces programmées
  const response = await client.spaces.search({
    query: "tech",
    state: "scheduled",
  });

  response.data?.forEach((space) => {
    console.log(`SCHEDULED: ${space.title}`);
  });
  ```
</CodeGroup>

***

<div id="include-host-information">
  ## Inclure les informations sur l'hôte
</div>

Inclure les données de l'utilisateur hôte :

<CodeGroup dropdown>
  ```bash cURL theme={null}
  curl "https://api.x.com/2/spaces/search?\
  query=AI&\
  space.fields=title,host_ids,state&\
  expansions=host_ids&\
  user.fields=username,verified" \
    -H "Authorization: Bearer $BEARER_TOKEN"
  ```

  ```python Python SDK theme={null}
  from xdk import Client

  client = Client(bearer_token="YOUR_BEARER_TOKEN")

  # Recherche avec informations sur l'hôte
  response = client.spaces.search(
      query="AI",
      space_fields=["title", "host_ids", "state"],
      expansions=["host_ids"],
      user_fields=["username", "verified"]
  )

  for space in response.data:
      print(f"{space.title}")
  # Les informations sur l'hôte se trouvent dans response.includes.users
  ```

  ```javascript JavaScript SDK theme={null}
  import { Client } from "@xdevplatform/xdk";

  const client = new Client({ bearerToken: "YOUR_BEARER_TOKEN" });

  // Recherche avec informations sur l'hôte
  const response = await client.spaces.search({
    query: "AI",
    spaceFields: ["title", "host_ids", "state"],
    expansions: ["host_ids"],
    userFields: ["username", "verified"],
  });

  response.data?.forEach((space) => {
    console.log(space.title);
  });
  // Les informations sur l'hôte se trouvent dans response.includes?.users
  ```
</CodeGroup>

***

<div id="common-parameters">
  ## Paramètres courants
</div>

| Paramètre      | Description                            |
| :------------- | :------------------------------------- |
| `query`        | Requête de recherche (obligatoire)     |
| `state`        | Filtre : `live`, `scheduled` ou `all`  |
| `max_results`  | Nombre de résultats à renvoyer (1-100) |
| `space.fields` | Champs Space à inclure                 |
| `expansions`   | Objets associés à inclure              |
| `user.fields`  | Champs utilisateur à inclure           |

***

<div id="next-steps">
  ## Prochaines étapes
</div>

<CardGroup cols={2}>
  <Card title="Recherche de Spaces" icon="microphone" href="/fr/x-api/spaces/lookup/quickstart">
    Rechercher des Spaces par identifiant
  </Card>

  <Card title="Référence de l’API" icon="code" href="/fr/x-api/spaces/search-spaces">
    Documentation complète de l’endpoint
  </Card>
</CardGroup>
