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

# Obtendo um relacionamento social

> Exemplo de código C simples da XSAPI que usa XblSocialGetSocialRelationshipsAsync para recuperar os amigos de um usuário do XBOX Live e as propriedades públicas do relacionamento.

<Note>Este tópico demonstra o uso avançado da API. Se você encontrar um cenário sem suporte no Social Manager, informe seu gerente de conta de desenvolvedor (DAM).</Note>

Este tópico fornece um exemplo de código que mostra como usar a API do Social Manager para recuperar os relacionamentos sociais de um usuário e as propriedades públicas deles.

Para começar a usar o Social Manager, consulte a [visão geral do Social Manager](/pt-BR/services/xbox-services/community/social-manager/live-social-manager-overview).
A API do Social Manager simplifica significativamente o desenvolvimento para acompanhar os amigos online e a atividade de jogo deles.

## Obtendo os relacionamentos sociais do primeiro usuário

O exemplo de código a seguir mostra como recuperar um relacionamento social com os serviços do XBOX.

O exemplo de código faz o seguinte:

1. Gera uma lista de todos os usuários no sistema e, em seguida, recupera o primeiro usuário.
2. Recupera todos os relacionamentos sociais desse usuário.
3. Exibe as propriedades públicas de cada um desses relacionamentos.

**API C simples**

```cpp theme={null}
auto asyncBlock = std::make_unique<XAsyncBlock>(); 
asyncBlock->queue = queue;
asyncBlock->context = nullptr;
asyncBlock->callback = [](XAsyncBlock* asyncBlock)
{
    std::unique_ptr<XAsyncBlock> asyncBlockPtr{ asyncBlock }; // Take over ownership of XAsyncBlock*.
    HRESULT hr = XblSocialGetSocialRelationshipsResult(asyncBlock, &state.socialResultHandle);

    // Be sure to call XblSocialRelationshipResultCloseHandle when the result object is no longer needed.
};

HRESULT hr = XblSocialGetSocialRelationshipsAsync(
    xboxLiveContext,
    xboxUserId,
    socialRelationshipFilter,
    0,
    0,
    asyncBlock.get()
);

if (SUCCEEDED(hr))
{
    // The call succeeded, so release the std::unique_ptr ownership of XAsyncBlock* because the callback will take over ownership.
    // If the call fails, std::unique_ptr will keep ownership and delete XAsyncBlock*.
    asyncBlock.release();
}
```

Para obter mais informações, consulte:

* [XAsyncBlock](/pt-BR/reference/system/xasync/structs/xasyncblock)
* [XblSocialGetSocialRelationshipsAsync](/pt-BR/reference/live/xsapi-c/social_c/functions/xblsocialgetsocialrelationshipsasync)
* [XblSocialGetSocialRelationshipsResult](/pt-BR/reference/live/xsapi-c/social_c/functions/xblsocialgetsocialrelationshipsresult)
* [XblSocialRelationshipResultCloseHandle](/pt-BR/reference/live/xsapi-c/social_c/functions/xblsocialrelationshipresultclosehandle)

## Obtendo um único relacionamento

**API C simples**

```cpp theme={null}
const XblSocialRelationship* relationships = nullptr;
size_t relationshipsCount = 0;
HRESULT hr = XblSocialRelationshipResultGetRelationships(state.socialResultHandle, &relationships, &relationshipsCount);

LogToFile("Got %u SocialRelationships:", relationshipsCount);
for (size_t i = 0; i < relationshipsCount; ++i)
{
    LogToFile("Xuid = %u, isFollowingCaller = %u", relationships[i].xboxUserId, relationships[i].isFollowingCaller);
}
```

Para obter mais informações, consulte:

* [XblSocialRelationship](/pt-BR/reference/live/xsapi-c/social_c/structs/xblsocialrelationship)
* [XblSocialRelationshipResultGetRelationships](/pt-BR/reference/live/xsapi-c/social_c/functions/xblsocialrelationshipresultgetrelationships)

## Obtendo a próxima página de relacionamentos

**API C simples**

```cpp theme={null}
bool hasNext{ false };
HRESULT hr = XblSocialRelationshipResultHasNext(state.socialResultHandle, &hasNext);

if (hasNext)
{
    auto asyncBlock = std::make_unique<XAsyncBlock>(); 
    asyncBlock->queue = queue;
    asyncBlock->context = nullptr;
    asyncBlock->callback = [](XAsyncBlock* asyncBlock)
    {
        std::unique_ptr<XAsyncBlock> asyncBlockPtr{ asyncBlock }; // Take over ownership of XAsyncBlock*.
        // Close the handle to the previous page of results.
        if (state.socialResultHandle)
        {
            XblSocialRelationshipResultCloseHandle(state.socialResultHandle);
        }
        HRESULT hr = XblSocialRelationshipResultGetNextResult(asyncBlock, &state.socialResultHandle);
    };

    uint32_t maxItems = 100;
    HRESULT hr = XblSocialRelationshipResultGetNextAsync(xboxLiveContext, state.socialResultHandle, maxItems, asyncBlock.get());
    if (SUCCEEDED(hr))
    {
        // The call succeeded, so release the std::unique_ptr ownership of XAsyncBlock* because the callback will take over ownership.
        // If the call fails, std::unique_ptr will keep ownership and delete XAsyncBlock*.
        asyncBlock.release();
    }
}
```

Para obter mais informações, consulte:

* [XAsyncBlock](/pt-BR/reference/system/xasync/structs/xasyncblock)
* [XblSocialRelationshipResultCloseHandle](/pt-BR/reference/live/xsapi-c/social_c/functions/xblsocialrelationshipresultclosehandle)
* [XblSocialRelationshipResultGetNextAsync](/pt-BR/reference/live/xsapi-c/social_c/functions/xblsocialrelationshipresultgetnextasync)
* [XblSocialRelationshipResultGetNextResult](/pt-BR/reference/live/xsapi-c/social_c/functions/xblsocialrelationshipresultgetnextresult)
* [XblSocialRelationshipResultHasNext](/pt-BR/reference/live/xsapi-c/social_c/functions/xblsocialrelationshipresulthasnext)


## Related topics

- [Código de exemplo do sistema de pessoas (lista de amigos)](/pt-BR/services/xbox-services/community/people-system/how-to/live-pplsys-howto-nav.md)
- [Instruções](/pt-BR/services/xbox-services/community/people-system/how-to/index.md)
- [Placares de líderes](/pt-BR/build/steam-porting-guide/features/steam-leaderboards.md)
- [Tratando uma alteração de relacionamento social](/pt-BR/services/xbox-services/community/people-system/how-to/live-handling-a-relationship-change.md)
- [Obtendo a presença de um usuário](/pt-BR/services/xbox-services/community/presence/how-to/live-getting-a-users-presence.md)
