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

取得客戶集合識別碼。接著，您可以使用此識別碼，透過 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](/zh-TW/reference/system/xstore/functions/xstorecreatecontext) 所傳回之使用者的市集內容控制代碼。

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

後端服務可用來授權使用者和服務的 Azure 票證。這可讓您從服務取回票證，然後轉送給您自己的伺服器。接著，您的伺服器可以儲存此票證，並將其用於 B2B 呼叫，以檢查擁有權或授與存取權。

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

由開發人員產生的字串，用來將目前使用者識別為屬於遊戲、開發人員或發行者之服務的成員或來賓。此字串的內容由開發人員決定，也可以保留空白。

*async*   \_Inout\_\
類型：[XAsyncBlock\*](/zh-TW/reference/system/xasync/structs/xasyncblock)

定義正在進行之非同步工作的 [XAsyncBlock](/zh-TW/reference/system/xasync/structs/xasyncblock)。[XAsyncBlock](/zh-TW/reference/system/xasync/structs/xasyncblock) 可用來輪詢呼叫的狀態並擷取呼叫結果。如需詳細資訊，請參閱 [XAsyncBlock](/zh-TW/reference/system/xasync/structs/xasyncblock)。

### 傳回值

類型：HRESULT

HRESULT 成功或錯誤碼。

## 備註

在 PC 上，如果已啟用 XBOX services，此 API 會傳回目前登入市集之使用者的資訊，而不一定是正在玩您遊戲的使用者。如果您的遊戲位於 XBOX 主機上，或在 PC 上啟用 XBOX services，建議您使用 XSTS 委派授權對集合和授權預覽端點進行 B2B 呼叫，以確保您檢查的是目前正在玩遊戲之使用者的權利。

若要擷取使用者的集合識別碼以及此函式的執行結果，請在呼叫此函式之後呼叫 [XStoreGetUserCollectionsIdResult](/zh-TW/reference/system/xstore/functions/xstoregetusercollectionsidresult)。若要擷取使用者集合識別碼的大小，請呼叫 [XStoreGetUserCollectionsIdResultSize](/zh-TW/reference/system/xstore/functions/xstoregetusercollectionsidresultsize)。知道結果的大小可讓您更有效率地擷取結果。

下列程式碼片段示範如何擷取客戶集合識別碼。

```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 主機

## 概念文件

* [要求使用者市集識別碼以進行服務對服務驗證](/zh-TW/publishing/xstore-commerce/xstore-requesting-userstoreid)

## 另請參閱

[XStore](/zh-TW/reference/system/xstore/xstore_members)\
[XStoreGetUserCollectionsIdResult](/zh-TW/reference/system/xstore/functions/xstoregetusercollectionsidresult)\
[從您的服務管理產品](https://learn.microsoft.com/gaming/gdk/docs/store/commerce/service-to-service/service-to-service-nav)


## Related topics

- [XStoreGetUserCollectionsIdAsync](/ja-jp/reference/system/xstore/functions/xstoregetusercollectionsidasync.md)
- [XStoreGetUserCollectionsIdResult](/reference/system/xstore/functions/xstoregetusercollectionsidresult.md)
