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

# XStoreGetUserCollectionsIdAsync

> XStoreGetUserCollectionsIdAsync

# XStoreGetUserCollectionsIdAsync

获取客户集合 ID。然后可使用此 ID 通过 B2B 调用从你自己的服务验证用户的权益。此 API 用于[通过你的服务管理产品](https://learn.microsoft.com/gaming/gdk/docs/store/commerce/service-to-service/service-to-service-nav)中概述的流程。

## 语法

```cpp theme={null}
HRESULT XStoreGetUserCollectionsIdAsync(  
         const XStoreContextHandle storeContextHandle,  
         const char* serviceTicket,  
         const char* publisherUserId,  
         XAsyncBlock* async  
)  
```

### 参数

*storeContextHandle*   \_In\_\
类型：XStoreContextHandle

由 [XStoreCreateContext](/reference/system/xstore/functions/xstorecreatecontext) 返回的用户的应用商店上下文句柄。

*serviceTicket*   \_In\_z\_\
类型：char\*

可供后端服务用于对用户和服务进行授权的 Azure 票证。这使你能够从服务取回一个票证，然后可以将该票证中继到你自己的服务器。然后你的服务器可以存储此票证并将其用于 B2B 调用，以检查所有权或授予访问权限。

*publisherUserId*   \_In\_z\_\
类型：char\*

由开发者生成的字符串，旨在将当前用户标识为游戏、开发者或发行商所拥有的服务的成员或访客。此字符串的内容由开发者决定，可以留空。

*async*   \_Inout\_\
类型：[XAsyncBlock\*](/reference/system/xasync/structs/xasyncblock)

定义正在执行的异步工作的 [XAsyncBlock](/reference/system/xasync/structs/xasyncblock)。可使用 [XAsyncBlock](/reference/system/xasync/structs/xasyncblock) 轮询调用状态并检索调用结果。有关详细信息，请参阅 [XAsyncBlock](/reference/system/xasync/structs/xasyncblock)。

### 返回值

类型：HRESULT

HRESULT 成功或错误代码。

## 备注

在 PC 上，如果启用了 XBOX services，则此 API 将返回当前登录到应用商店的用户的信息，而不一定是玩游戏的用户的信息。如果你的游戏运行在 XBOX 主机上，或者在 PC 上启用了 XBOX services，我们建议使用 XSTS 委托授权对集合和许可证预览终结点进行 B2B 调用，以确保检查的是当前正在玩游戏的用户的权益。

要检索用户的集合 ID 以及此函数的执行结果，请在调用此函数后调用 [XStoreGetUserCollectionsIdResult](/reference/system/xstore/functions/xstoregetusercollectionsidresult)。要检索用户集合 ID 的大小，请调用 [XStoreGetUserCollectionsIdResultSize](/reference/system/xstore/functions/xstoregetusercollectionsidresultsize)。知道结果的大小可让你更高效地检索结果。

以下代码片段演示了检索客户集合 ID 的示例。

```cpp theme={null}
void CALLBACK GetUserCollectionsIdCallback(XAsyncBlock* asyncBlock)
{
    size_t size;
    HRESULT hr = XStoreGetUserCollectionsIdResultSize(
        asyncBlock,
        &size);

    if (FAILED(hr))
    {
        printf("Failed retrieve the user collection ID size: 0x%x\r\n", hr);
        return;
    }

    char* result = new char[size];
    hr = XStoreGetUserCollectionsIdResult(
        asyncBlock,
        size,
        result);

    if (FAILED(hr))
    {
        printf("Failed retrieve the user collection ID result: 0x%x\r\n", hr);
        delete[] result;
        return;
    }

    printf("result: %s\r\n", result);

    delete[] result;
}

void GetUserCollectionsId(XStoreContextHandle storeContextHandle, XTaskQueueHandle taskQueueHandle, const char* serviceTicket, const char* publisherUserId)
{
    auto asyncBlock = std::make_unique<XAsyncBlock>();
    ZeroMemory(asyncBlock.get(), sizeof(*asyncBlock));
    asyncBlock->queue = taskQueueHandle;
    asyncBlock->callback = GetUserCollectionsIdCallback;

    HRESULT hr = XStoreGetUserCollectionsIdAsync(
        storeContextHandle,
        serviceTicket,
        publisherUserId,
        asyncBlock.get());

    if (FAILED(hr))
    {
        printf("Failed to get user collections ID: 0x%x\r\n", hr);
        return;
    }
}
```

## 要求

**头文件：** XStore.h（包含于 XGameRuntime.h 中）

**库：** xgameruntime.lib

**支持的平台：** Windows、XBOX One 系列主机和 XBOX Series 主机

## 概念文档

* [请求用于服务到服务身份验证的 User Store ID](https://learn.microsoft.com/gaming/gdk/docs/store/commerce/service-to-service/xstore-requesting-a-userstoreid)

## 另请参阅

[XStore](/reference/system/xstore/xstore_members)\
[XStoreGetUserCollectionsIdResult](/reference/system/xstore/functions/xstoregetusercollectionsidresult)\
[通过你的服务管理产品](https://learn.microsoft.com/gaming/gdk/docs/store/commerce/service-to-service/service-to-service-nav)


## Related topics

- [XStoreGetUserCollectionsIdResult](/zh-CN/reference/system/xstore/functions/xstoregetusercollectionsidresult.md)
- [XStoreGetUserCollectionsIdResultSize](/zh-CN/reference/system/xstore/functions/xstoregetusercollectionsidresultsize.md)
- [为服务到服务身份验证请求 User Store ID](/zh-CN/publishing/xstore-commerce/xstore-requesting-userstoreid.md)
- [XStore 商务概述](/zh-CN/publishing/xstore-commerce/xstore-commerce-overview.md)
- [XStore](/zh-CN/reference/system/xstore/xstore_members.md)
