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

# PlayFab GDPR - 刪除玩家資料

> 如何刪除 PlayFab 玩家資料以符合 GDPR 規範，包括使用 DeleteMasterPlayerAccount 移除帳戶，或在保留帳戶的同時清除資料。

# 刪除玩家資料

本文說明從 PlayFab 刪除玩家資料的兩種主要方式。您可以[刪除整個玩家帳戶](#delete-a-player-account)，或只[刪除資料而不刪除帳戶](#delete-account-data-without-deleting-the-account)。

## 刪除玩家帳戶

<Warning>
  刪除主要玩家帳戶會從 PlayFab 刪除與該玩家相關聯的所有資料，等同於從您的遊戲中刪除該玩家。DeleteMasterPlayerAccount API 沒有選擇性刪除玩家相關資料的機制。如需刪除資料並保留玩家帳戶的選項，請參閱「刪除事件資料」和「刪除自訂資料」。
</Warning>

您可以使用 [DeleteMasterPlayerAccount](https://learn.microsoft.com/en-us/rest/api/playfab/admin/account-management/delete-master-player-account) Admin API 來刪除主要玩家帳戶及其資料，我們所有的 SDK 都提供此 API。請閱讀[確定您找到所有資料](/zh-TW/services/playfab/data-analytics/privacy-compliance/playfab-gdpr-deleting-and-exporting-player-data)。

當您提出刪除玩家的要求時，PlayFab 會先快速從我們的核心系統移除玩家的個人資訊，再將要求傳送給佇列處理代理程式，由其負責從附屬系統和次級處理者移除玩家的任何剩餘資訊。

此 API 會立即傳回，並提供 `JobReceiptId`，您應該將其儲存以供記錄。JobReceiptId 是 PlayFab 已收到刪除玩家要求的驗證。

刪除完成後，系統會傳送電子郵件至為遊戲設定的通知電子郵件地址。其中包含 API 最初傳回的相同 `JobReceiptId`。工作完成也會觸發 PlayStream 事件。

使用我們的 Webhook 功能，您可以註冊在您選擇的端點上接收這些事件，並視需要處理它們。該事件會包含具有 `JobReceiptId` 的 JSON Blob。

下列範例示範如何搭配 [C# SDK](/zh-TW/services/playfab/sdks/c-sharp) 使用 Admin API。如果您想使用不同的 SDK，請從 [PlayFab SDK](/zh-TW/services/playfab/sdks/playfab-sdk-intro) 清單中選取一個。

```csharp theme={null}
public static async void StartDeleteMasterPlayerExample(Action<PlayFabError> callback)
{
    var task = await PlayFabAdminAPI.DeleteMasterPlayerAccountAsync(new DeleteMasterPlayerAccountRequest()
    {
        PlayFabId = PlayFabId
    });

    if(task.Error != null)
    {
        callback(task.Error);
    }

    var jobReceiptId = task.Result.JobReceiptId;
    var AffectedTitleList = task.Result.TitleIds; 
    foreach (var title in AffectedTitleList)
    {
        Console.WriteLine(string.Format("Delete Player - Title Affected: {0}", title));
    }

}
```

<Note>
  由於此刪除*無法復原*，建議您與玩家確認他們能接受其刪除要求的範圍和影響。
</Note>

確認動作後，使用下列程式碼繼續刪除主要玩家帳戶。

```csharp theme={null}
//Make sure we are 100% sure we want to do this.
if ( confirm successful ) {
   //create a variable to store a list of titles the player has already been removed from.
   listOfTitlesRemovedFrom
   //Hang on to the receipts from successful deletes.
   listOfReceipts
   foreach(title in <all my titles>){

       //You only need to remove the Master Player once per namespace, so check that you have not
       //already performed this action in the namespace, or you will get an error that
       //the player is already queued for deletion.
       if(title not in listOfTitlesRemovedFrom){
           foreach(pfid in PlayFabIdList){

              //Note: you should do some error handling around this API call.
              response = title.DeleteMasterPlayerAccount(pfid)
              foreach(titleId in response.titleids){
                listOfTitlesRemoved.add(titleId)
              }
              listOfReceipts.add(response.jobreceiptid)
           }
       }
   }

   //Save listOfReceipts somewhere as proof of deletion.

}
```

## 刪除帳戶資料而不刪除帳戶

使用此清單協助您刪除與玩家帳戶相關聯的事件資料。

### 刪除事件資料

事件資料包括 PlayStream 事件和遙測。事件資料屬於交易性資料，由使用者活動產生。

#### PlayFab Insights

PlayFab Insights 是完全受控的解決方案，由 PlayFab 代表您儲存事件資料。

當玩家提出要求時，您可以使用 [DeleteMasterPlayerEventData](https://learn.microsoft.com/en-us/rest/api/playfab/admin/account-management/delete-master-player-event-data) API 刪除 Insights 資料。這只會刪除 PlayFab Insights 中與該玩家相關的已儲存資料，其他所有資料則保持不變。

### 刪除自訂資料

自訂資料是指一大類功能，可讓您將任意資料與玩家建立關聯。PlayFab 提供從遊戲邏輯與資料互動的方法，但不會以其他方式解譯或理解這些資料。

#### 舊版玩家資料

您可以使用下列 API 編輯和刪除不同類型的玩家資料：

[UpdateUserData](https://learn.microsoft.com/en-us/rest/api/playfab/server/player-data-management/update-user-data), [UpdateUserInternalData](https://learn.microsoft.com/en-us/rest/api/playfab/server/player-data-management/update-user-internal-data), [UpdateUserReadOnlyData](https://learn.microsoft.com/en-us/rest/api/playfab/server/player-data-management/update-user-read-only-data), [UpdateUserPublisherData](https://learn.microsoft.com/en-us/rest/api/playfab/server/player-data-management/update-user-publisher-data), [UpdateUserPublisherInternalData](https://learn.microsoft.com/en-us/rest/api/playfab/server/player-data-management/update-user-publisher-internal-data), [UpdateUserPublisherReadOnlyData](https://learn.microsoft.com/en-us/rest/api/playfab/server/player-data-management/update-user-publisher-read-only-data)

這些 API 都會接受參數 **KeysToRemove**，該參數接受應從玩家設定檔中刪除的玩家資料索引鍵清單。

#### 實體物件

您可以使用 SetObjects API 刪除[實體物件](/zh-TW/services/playfab/live-service-management/game-configuration/entities/entity-objects)。在要求本文的 Objects 陣列中，為每個要刪除的物件建立一個項目，方法是指定其 ObjectName 並將 DeleteObject 設定為 true。以下是要求本文的範例。

```HTTP theme={null}
{ 
    "Entity": { 
        "Id": "<The ID of the target entity>", 
        "Type": "<either ‘title_player_account’, ‘master_player_account’, or ‘character’>" 
    }, 
    "Objects": [ 
        { 
            "ObjectName": "<Name of object to delete>", 
            "DeleteObject": true 
        } 
    ] 
} 
```

#### 實體檔案

[實體檔案](/zh-TW/services/playfab/live-service-management/game-configuration/entities/entity-files)是使用 [DeleteFiles](https://learn.microsoft.com/en-us/rest/api/playfab/data/file/delete-files) API 刪除。


## Related topics

- [PlayFab GDPR - 刪除和匯出玩家資料](/zh-TW/services/playfab/data-analytics/privacy-compliance/playfab-gdpr-deleting-and-exporting-player-data.md)
- [PlayFab GDPR - 匯出玩家資料](/zh-TW/services/playfab/data-analytics/privacy-compliance/gdpr-exporting-player-data.md)
- [PlayFab 玩家進度文件](/zh-TW/services/playfab/player-progression/index.md)
- [PlayFab 資料與分析文件](/zh-TW/services/playfab/data-analytics/index.md)
- [玩家資料](/zh-TW/services/playfab/player-progression/player-data/index.md)
