> ## 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](/zh-TW/reference/system/xuser/functions/xusergettokenandsignatureasync) 之結果的緩衝區大小。

## 語法

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

### 參數

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

用於輪詢呼叫狀態並擷取呼叫結果的 [XAsyncBlock](/zh-TW/reference/system/xasync/structs/xasyncblock)。

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

包含所需的緩衝區大小。

### 傳回值

類型：HRESULT

如果成功，則傳回 S\_OK；否則傳回錯誤碼。
如需錯誤碼清單，請參閱[錯誤碼](/zh-TW/reference/errorcodes)。

## 備註

若要以非同步方式擷取 Web 要求的 X 權杖和簽章，請呼叫 [XUserGetTokenAndSignatureAsync](/zh-TW/reference/system/xuser/functions/xusergettokenandsignatureasync)。

若要擷取呼叫 [XUserGetTokenAndSignatureAsync](/zh-TW/reference/system/xuser/functions/xusergettokenandsignatureasync) 的結果，請呼叫 [XUserGetTokenAndSignatureResult](/zh-TW/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](/zh-TW/reference/system/xuser/xuser_members)

[XUserGetTokenAndSignatureAsync](/zh-TW/reference/system/xuser/functions/xusergettokenandsignatureasync)

[XUserGetTokenAndSignatureResult](/zh-TW/reference/system/xuser/functions/xusergettokenandsignatureresult)


## Related topics

- [XUserGetTokenAndSignatureResultSize](/reference/system/xuser/functions/xusergettokenandsignatureresultsize.md)
- [XUserGetTokenAndSignatureResult](/reference/system/xuser/functions/xusergettokenandsignatureresult.md)
- [XUserGetTokenAndSignatureAsync](/reference/system/xuser/functions/xusergettokenandsignatureasync.md)
- [XUser](/reference/system/xuser/xuser_members.md)
- [XUserGetTokenAndSignatureUtf16ResultSize](/reference/system/xuser/functions/xusergettokenandsignatureutf16resultsize.md)
