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

# PFAuthenticationLoginWithGoogleAccountAsync

> 使用用户的 Google 帐户凭据为用户登录

使用用户的 Google 帐户凭据为用户登录

## 语法

```cpp theme={null}
HRESULT PFAuthenticationLoginWithGoogleAccountAsync(  
    PFServiceConfigHandle serviceConfigHandle,  
    const PFAuthenticationLoginWithGoogleAccountRequest* request,  
    XAsyncBlock* async  
)  
```

### 参数

**`serviceConfigHandle`**   PFServiceConfigHandle

从 PFServiceConfigCreateHandle 调用返回的 PFServiceConfigHandle。

**`request`**   [PFAuthenticationLoginWithGoogleAccountRequest\*](/services/playfab/api-references/c/pfauthenticationtypes/structs/pfauthenticationloginwithgoogleaccountrequest)

已填充的请求对象。

**`async`**   XAsyncBlock\*<br />*Inout*

用于异步操作的 XAsyncBlock。

### 返回值

类型：HRESULT

此 API 操作的结果代码。

## 备注

此 API 可在 Android 上使用。Google 登录通过在设备上使用适用于 Android API 的 Google 登录获取 Google OAuth 2.0 凭据，然后将其传递给此 API 来完成。如果这是用户首次使用 Google 帐户登录且 CreateAccount 设为 true，将创建一个新的 PlayFab 帐户并链接到该 Google 帐户。否则，如果没有 PlayFab 帐户链接到该 Google 帐户，将返回相应的错误，以便游戏引导用户创建 PlayFab 帐户。目前（推荐）在 Android 应用程序中获取 Google 帐户凭据的方法是调用 GoogleSignInAccount.getServerAuthCode() 并将授权代码作为此 API 的 ServerAuthCode 参数发送。在执行此操作之前，必须在 Google API 控制台中创建 OAuth 2.0 Web 应用程序客户端 ID，并在 PlayFab Game Manager Google 加载项中为你的游戏配置其客户端 ID 和密钥。此方法无需向用户提示其他 Google 帐户权限，因此可获得摩擦最少的用户体验。有关获取服务器授权代码的详细信息，请参阅 [https://developers.google.com/identity/sign-in/android/offline-access](https://developers.google.com/identity/sign-in/android/offline-access)。以前（已弃用）的方法是通过在客户端上调用 GetAccessToken() 获取 OAuth 访问令牌，并将其作为 AccessToken 参数传递给此 API，用于 Google OAuth 2.0 访问令牌。有关此更改的详细信息，请参阅 Google 开发人员文档 ([https://android-developers.googleblog.com/2016/01/play-games-permissions-are-changing-in.html](https://android-developers.googleblog.com/2016/01/play-games-permissions-are-changing-in.html))。异步任务完成后，调用 [PFAuthenticationLoginWithGoogleAccountGetResult](/services/playfab/api-references/c/pfauthentication/functions/pfauthenticationloginwithgoogleaccountgetresult) 获取结果。

## 要求

**头文件：** PFAuthentication.h

## 另请参阅

[PFAuthentication 成员](/services/playfab/api-references/c/pfauthentication/pfauthentication_members)


## Related topics

- [PFAuthenticationLoginWithGoogleAccountGetResultSize](/zh-CN/services/playfab/api-references/c/pfauthentication/functions/pfauthenticationloginwithgoogleaccountgetresultsize.md)
- [PFAuthenticationLoginWithGoogleAccountGetResult](/zh-CN/services/playfab/api-references/c/pfauthentication/functions/pfauthenticationloginwithgoogleaccountgetresult.md)
- [服务 C API 概览 - PFAuthentication.h](/zh-CN/services/playfab/api-references/c/pfauthentication/pfauthentication_members.md)
- [PFAuthenticationReLoginWithGoogleAccountAsync](/zh-CN/services/playfab/api-references/c/pfauthentication/functions/pfauthenticationreloginwithgoogleaccountasync.md)
- [PFAuthenticationLoginWithGoogleAccountRequest](/zh-CN/services/playfab/api-references/c/pfauthenticationtypes/structs/pfauthenticationloginwithgoogleaccountrequest.md)
