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

# XUserGetTokenAndSignatureResultSize

> XUserGetTokenAndSignatureResultSize

# XUserGetTokenAndSignatureResultSize

获取用于存放调用 [XUserGetTokenAndSignatureAsync](/reference/system/xuser/functions/xusergettokenandsignatureasync) 结果的缓冲区大小。

## 语法

```cpp theme={null}
HRESULT XUserGetTokenAndSignatureResultSize(  
         XAsyncBlock* async,  
         size_t* bufferSize  
)  
```

### 参数

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

用于轮询调用状态并检索调用结果的 [XAsyncBlock](/reference/system/xasync/structs/xasyncblock)。

*bufferSize*   \_Out\_\
类型：size\_t\*

包含所需的缓冲区大小。

### 返回值

类型：HRESULT

如果成功，则返回 S\_OK；否则返回错误代码。
有关错误代码列表，请参阅[错误代码](/reference/errorcodes)。

## 注解

若要以异步方式检索 Web 请求的 xtoken 和签名，请调用 [XUserGetTokenAndSignatureAsync](/reference/system/xuser/functions/xusergettokenandsignatureasync)。

若要检索调用 [XUserGetTokenAndSignatureAsync](/reference/system/xuser/functions/xusergettokenandsignatureasync) 的结果，请调用 [XUserGetTokenAndSignatureResult](/reference/system/xuser/functions/xusergettokenandsignatureresult)。

以下示例演示如何以异步方式检索用户的令牌和签名。

```cpp theme={null}
HRESULT RequestTokenComplete(XAsyncBlock* abResult)
{
    size_t bufferSize;
    RETURN_IF_FAILED(XUserGetTokenAndSignatureResultSize(abResult, &bufferSize));

    std::vector<uint8_t> buffer(bufferSize);
    XUserGetTokenAndSignatureData* data;
    if (SUCCEEDED_LOG(XUserGetTokenAndSignatureResult(abResult, buffer.size(), buffer.data(), &data, nullptr /*bufferUsed*/)))
    {
        appLog.AddLog("Token: %s\n", data->token);
        if (data->signature != nullptr)
        {    
            appLog.AddLog("Signature: %s\n", data->signature);
        }
    }

    return S_OK;
}

HRESULT RequestTokenAsync(
    XTaskQueueHandle queue,
    const char* url,
    bool forceRefresh)
{
    auto asyncBlock = std::make_unique<XAsyncBlock>();
    ZeroMemory(asyncBlock.get(), sizeof(*asyncBlock));
    asyncBlock->queue = queue;
    asyncBlock->context = this;
    asyncBlock->callback = [](XAsyncBlock* ab)
    {
        LOG_IF_FAILED(static_cast<User*>(ab->context)->RequestTokenComplete(ab));
        delete ab;
    };


    XUserGetTokenAndSignatureOptions options = XUserGetTokenAndSignatureOptions::None;

    if (forceRefresh)
    {
        WI_SET_FLAG(options, XUserGetTokenAndSignatureOptions::ForceRefresh);
    }

    static const XUserGetTokenAndSignatureHttpHeader headers[] =
    {
        { "Accept", "application/json"},
        { "Why", "Because"},
    };

    if (SUCCEEDED_LOG(XUserGetTokenAndSignatureAsync(
        _handle.get(),
        options,
        "GET",
        url,
        ARRAYSIZE(headers),
        headers,
        0,
        nullptr,
        asyncBlock.get())))
    {
        // The call succeeded, so release the std::unique_ptr ownership of XAsyncBlock* since the callback will take over ownership.
        // If the call fails, the std::unique_ptr will keep ownership and delete the XAsyncBlock*
        asyncBlock.release();
    }

    return S_OK;
}
```

## 要求

**头文件：** XUser.h

**库：** xgameruntime.lib

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

## 另请参阅

[XUser](/reference/system/xuser/xuser_members)

[XUserGetTokenAndSignatureAsync](/reference/system/xuser/functions/xusergettokenandsignatureasync)

[XUserGetTokenAndSignatureResult](/reference/system/xuser/functions/xusergettokenandsignatureresult)


## Related topics

- [XUserGetTokenAndSignatureResult](/zh-CN/reference/system/xuser/functions/xusergettokenandsignatureresult.md)
- [XUserGetTokenAndSignatureAsync](/zh-CN/reference/system/xuser/functions/xusergettokenandsignatureasync.md)
- [XUser](/zh-CN/reference/system/xuser/xuser_members.md)
- [面向 GDK 的 Unity C# API 包装器](/zh-CN/build/gdk-and-engines/unity/unity-api-wrappers.md)
- [XUserGetTokenAndSignatureUtf16ResultSize](/zh-CN/reference/system/xuser/functions/xusergettokenandsignatureutf16resultsize.md)
