> ## 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\_\
Type: XStoreContextHandle

[XStoreCreateContext](/reference/system/xstore/functions/xstorecreatecontext) から返される、ユーザーのストア コンテキスト ハンドル。

*serviceTicket*   \_In\_z\_\
Type: char\*

バックエンド サービスがユーザーとサービスを認可するために使用できる Azure チケット。これにより、サービスからチケットを取得して独自のサーバーに中継できます。その後、サーバーはこれを保存し、所有権のチェックやアクセスの付与を行う B2B 呼び出しに使用できます。

*publisherUserId*   \_In\_z\_\
Type: char\*

現在のユーザーを、ゲーム、開発者、またはパブリッシャーに属するサービスのメンバーまたはゲストとして識別することを目的として、開発者によって生成される文字列。この文字列の内容は開発者によって決定され、空欄のままにすることもできます。

*async*   \_Inout\_\
Type: [XAsyncBlock\*](/reference/system/xasync/structs/xasyncblock)

実行中の非同期処理を定義する [XAsyncBlock](/reference/system/xasync/structs/xasyncblock)。[XAsyncBlock](/reference/system/xasync/structs/xasyncblock) は、呼び出しの状態のポーリングと呼び出し結果の取得に使用できます。詳細については、[XAsyncBlock](/reference/system/xasync/structs/xasyncblock) を参照してください。

### 戻り値

Type: HRESULT

HRESULT の成功またはエラー コード。

## 解説

PC では、XBOX サービスが有効な場合、この API はストアに現在サインインしているユーザーの情報を返し、必ずしもゲームをプレイしているユーザーの情報を返すとは限りません。タイトルが XBOX コンソール上にあるか、PC で XBOX サービスが有効になっている場合は、実際にプレイしているユーザーの権利を確認するために、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 本体

## 関連概念ドキュメント

* [サービス間認証用のユーザー ストア 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](/ja-jp/reference/system/xstore/functions/xstoregetusercollectionsidresult.md)
- [XStoreGetUserCollectionsIdResultSize](/ja-jp/reference/system/xstore/functions/xstoregetusercollectionsidresultsize.md)
- [サービス間認証用のユーザー Store ID を要求する](/ja-jp/publishing/xstore-commerce/xstore-requesting-userstoreid.md)
- [XStore コマースの概要](/ja-jp/publishing/xstore-commerce/xstore-commerce-overview.md)
- [XStore](/ja-jp/reference/system/xstore/xstore_members.md)
