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

# Getting a social relationship

> Sample XSAPI flat C code that uses XblSocialGetSocialRelationshipsAsync to retrieve an XBOX Live user's friends and their public relationship properties.

<Note>This topic demonstrates advanced API usage. If you find an unsupported scenario in the Social Manager, please let your developer account manager (DAM) know.</Note>

This topic provides a code example that shows how to use the Social Manager API to retrieve a user's social relationships and their public properties.

To get started with the Social Manager, see [Social Manager overview](/services/xbox-services/community/social-manager/live-social-manager-overview).
The Social Manager API significantly simplifies development for keeping track of online friends and their gaming activity.

## Getting the first user's social relationships

The following code example shows how to retrieve a social relationship with XBOX services.

The code example does the following:

1. Generates a list of all the users on the system, and then retrieves the first user.
2. Retrieves all of that user's social relationships.
3. Displays the public properties of each of those relationships.

**Flat C API**

```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();
}
```

For more information, see the following:

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

## Getting a single relationship

**Flat C API**

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

For more information, see the following:

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

## Getting the next page of relationships

**Flat C API**

```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();
    }
}
```

For more information, see the following:

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


## Related topics

- [People System (Friends List) example code](/services/xbox-services/community/people-system/how-to/live-pplsys-howto-nav.md)
- [How to](/services/xbox-services/community/people-system/how-to/index.md)
- [XblSocialRelationship](/reference/live/xsapi-c/social_c/structs/xblsocialrelationship.md)
- [XblSocialRelationshipResultGetRelationships](/reference/live/xsapi-c/social_c/functions/xblsocialrelationshipresultgetrelationships.md)
- [Handling a social relationship change](/services/xbox-services/community/people-system/how-to/live-handling-a-relationship-change.md)
