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

# 소셜 관계 가져오기

> XblSocialGetSocialRelationshipsAsync를 사용하여 XBOX Live 사용자의 친구와 공개 관계 속성을 검색하는 XSAPI flat C 코드 샘플입니다.

<Note>이 항목은 고급 API 사용법을 보여줍니다. Social Manager에서 지원되지 않는 시나리오를 발견하면 개발자 계정 관리자(DAM)에게 알려주세요.</Note>

이 항목에서는 Social Manager API를 사용하여 사용자의 소셜 관계와 그 공개 속성을 검색하는 방법을 보여주는 코드 예제를 제공합니다.

Social Manager를 시작하려면 [Social Manager 개요](/services/xbox-services/community/social-manager/live-social-manager-overview)를 참조하세요.
Social Manager API는 온라인 친구와 그들의 게임 활동을 추적하기 위한 개발을 크게 단순화합니다.

## 첫 번째 사용자의 소셜 관계 가져오기

다음 코드 예제에서는 XBOX 서비스에서 소셜 관계를 검색하는 방법을 보여줍니다.

코드 예제는 다음을 수행합니다.

1. 시스템의 모든 사용자 목록을 생성한 다음 첫 번째 사용자를 검색합니다.
2. 해당 사용자의 모든 소셜 관계를 검색합니다.
3. 각 관계의 공개 속성을 표시합니다.

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

자세한 내용은 다음을 참조하세요.

* [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)

## 단일 관계 가져오기

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

자세한 내용은 다음을 참조하세요.

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

## 관계 다음 페이지 가져오기

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

자세한 내용은 다음을 참조하세요.

* [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 시스템(친구 목록) 예제 코드](/ko/services/xbox-services/community/people-system/how-to/live-pplsys-howto-nav.md)
- [방법](/ko/services/xbox-services/community/people-system/how-to/index.md)
- [이벤트 기반 통계 가져오기](/ko/services/xbox-services/player-data/stats-leaderboards/event-based/how-to/live-getting-eb-stat.md)
- [리더보드](/ko/build/steam-porting-guide/features/steam-leaderboards.md)
- [타이틀 관리형 업적 가져오기](/ko/services/xbox-services/player-data/achievements/title-managed/how-to/live-how-to-get-achievements.md)
