> ## Documentation Index
> Fetch the complete documentation index at: https://docs.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)에게 알려주세요.

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

Social Manager를 시작하려면 [Social Manager 개요](https://docs.xbox.com/ko/services/xbox-services/community/social-manager/live-social-manager-overview.md)를 참조하세요.
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](https://docs.xbox.com/ko/reference/system/xasync/structs/xasyncblock.md)
* [XblSocialGetSocialRelationshipsAsync](https://docs.xbox.com/ko/reference/live/xsapi-c/social_c/functions/xblsocialgetsocialrelationshipsasync.md)
* [XblSocialGetSocialRelationshipsResult](https://docs.xbox.com/ko/reference/live/xsapi-c/social_c/functions/xblsocialgetsocialrelationshipsresult.md)
* [XblSocialRelationshipResultCloseHandle](https://docs.xbox.com/ko/reference/live/xsapi-c/social_c/functions/xblsocialrelationshipresultclosehandle.md)

## 단일 관계 가져오기

**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](https://docs.xbox.com/ko/reference/live/xsapi-c/social_c/structs/xblsocialrelationship.md)
* [XblSocialRelationshipResultGetRelationships](https://docs.xbox.com/ko/reference/live/xsapi-c/social_c/functions/xblsocialrelationshipresultgetrelationships.md)

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

**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](https://docs.xbox.com/ko/reference/system/xasync/structs/xasyncblock.md)
* [XblSocialRelationshipResultCloseHandle](https://docs.xbox.com/ko/reference/live/xsapi-c/social_c/functions/xblsocialrelationshipresultclosehandle.md)
* [XblSocialRelationshipResultGetNextAsync](https://docs.xbox.com/ko/reference/live/xsapi-c/social_c/functions/xblsocialrelationshipresultgetnextasync.md)
* [XblSocialRelationshipResultGetNextResult](https://docs.xbox.com/ko/reference/live/xsapi-c/social_c/functions/xblsocialrelationshipresultgetnextresult.md)
* [XblSocialRelationshipResultHasNext](https://docs.xbox.com/ko/reference/live/xsapi-c/social_c/functions/xblsocialrelationshipresulthasnext.md)


## Related topics

- [People System(친구 목록) 예제 코드(목차)](https://docs.xbox.com/ko/services/xbox-services/community/people-system/how-to/live-pplsys-howto-nav.md)
- [방법](https://docs.xbox.com/ko/services/xbox-services/community/people-system/how-to/index.md)
- [개체 가져오기](https://docs.xbox.com/ko/services/playfab/api-references/rest/data/object/get-objects.md)
- [정책 가져오기](https://docs.xbox.com/ko/services/playfab/api-references/rest/admin/authentication/get-policy.md)
- [그룹 가져오기](https://docs.xbox.com/ko/services/playfab/api-references/rest/groups/groups/get-group.md)
