> For the complete documentation index, see [llms.txt](https://docs.decentraland.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.decentraland.org/contributor/contributor-pt/servico-social/get-friends.md).

# Obter amigos

Detalhes sobre o uso da API do Social Service para recuperar friendships, requests e mutual friends na plataforma Decentraland. A API permite que os developers interajam com o Social Service para recuperar informações relacionadas a friendships.

#### REST API

Para recuperar friendships, o Social Service expõe uma [REST API](https://social-service-api-specs.pages.dev/):

* `GET /friendships/me` - Recupera as friendships do usuário atual. Requer o access token no cabeçalho Authorization.
* `GET /friendships/{other-address}/mutuals` - Recupera mutual friends com outro usuário. Requer o access token no cabeçalho Authorization.

#### Servidor RPC WebSocket

A API WebSocket do Social Service fornece dois tipos de mensagem para recuperar friendships e mutual friends. Primeiro, você precisa estabelecer uma conexão WebSocket e depois usar esses métodos para stream de informações relacionadas ao usuário.

* `GetFriends` - Recupera os friends de um usuário. Retorna um stream de respostas do usuário.
* `GetMutualFriends` - Recupera mutual friends com outro usuário. Retorna um stream de respostas do usuário.

Consulte o [arquivo friendships.proto](https://github.com/decentraland/protocol/blob/main/proto/decentraland/social/friendships/friendships.proto#L7) para mais detalhes sobre esses tipos de mensagem.

### Exemplos de Código em JavaScript

Para interagir com a API WebSocket do Social Service usando JavaScript, você pode usar o RPC client fornecido, como explicado anteriormente. Mas, se precisar implementá-la você mesmo, abaixo há exemplos de código demonstrando como recuperar friends e mutual friends:

#### Obtendo Todos os Friends

```javascript
import { createRpcClient, createWebSocketsTransport } from '@dcl/rpc/dist/client';
import { FriendshipsServiceDefinition } from './protobuff-types/decentraland/social/friendships/friendships.gen';

const socialClientRpcUrl = 'wss://social.decentraland.org'; // Substitua pela URL real
const webSocketsTransport = createWebSocketsTransport(socialClientRpcUrl);
const service = loadService(FriendshipsServiceDefinition, webSocketsTransport);

const response = service.getFriends(Payload.create({ synapseToken }));
for await (const friends of response) {
  processErrors(friends);
  const userList = friends.users?.users ?? [];
  // Processa a lista de friends
}
```

#### Obtendo Mutual Friends

```javascript
const response = service.getMutualFriends(
  MutualFriendsPayload.create({
    user: { address }, 
    authToken: { synapseToken }
  })
);
for await (const mutualFriend of response) {
  processErrors(mutualFriend);
  const mutualFriendList = mutualFriend.users?.users ?? [];
  // Processa a lista de mutual friends
}
```

Para mais exemplos de código e detalhes, visite o [repositório GitHub social-rpc-client-js](https://github.com/decentraland/social-rpc-client-js)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.decentraland.org/contributor/contributor-pt/servico-social/get-friends.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
