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

# ソーシャル リレーションシップ変更の処理

> XBOX Live のソーシャル リレーションシップ変更イベントを購読し、ユーザーのフレンド リストが更新されたときにハンドラーを追加または削除するための XSAPI コードです。

このトピックでは、ソーシャル リレーションシップの変更を処理するためのサンプル コードを提供します。

## リレーションシップ変更の購読

**フラット C API**

```cpp theme={null}
HRESULT hr = XblSocialSubscribeToSocialRelationshipChange(
    xboxLiveContext, 
    xboxUserId,
    &state.socialSubscriptionHandle
);
```

## リレーションシップ変更の購読解除

**フラット C API**

```cpp theme={null}
HRESULT hr = XblSocialUnsubscribeFromSocialRelationshipChange(
    xboxLiveContext, 
    state.socialSubscriptionHandle
);

state.socialSubscriptionHandle = nullptr;
```

## リレーションシップ変更ハンドラーの追加

**フラット C API**

```cpp theme={null}
state.socialRelationshipChangedHandlerToken = XblSocialAddSocialRelationshipChangedHandler(
    xboxLiveContext,
    [](const XblSocialRelationshipChangeEventArgs* args, void* context)
    {
        UNREFERENCED_PARAMETER(context);
        LogToFile("Social relationship changed:");
        std::stringstream ss;
        for (size_t i = 0; i < args->xboxUserIdsCount; ++i)
        {
            if (i > 0) 
            {
                ss << ", ";
            }
            ss << args->xboxUserIds[i];
        }
        LogToFile("socialNotification = %u, affectedXuids = %s", args->socialNotification, ss.str().data());
    },
    nullptr
);
```

## リレーションシップ変更ハンドラーの削除

**フラット C API**

```cpp theme={null}
HRESULT hr = XblSocialRemoveSocialRelationshipChangedHandler(xboxLiveContext, state.socialRelationshipChangedHandlerToken);
state.socialRelationshipChangedHandlerToken = 0;
```

## 関連項目

[XblSocialAddSocialRelationshipChangedHandler](/reference/live/xsapi-c/social_c/functions/xblsocialaddsocialrelationshipchangedhandler)
[XblSocialRemoveSocialRelationshipChangedHandler](/reference/live/xsapi-c/social_c/functions/xblsocialremovesocialrelationshipchangedhandler)


## Related topics

- [ピープル システム (フレンド リスト) のサンプル コード](/ja-jp/services/xbox-services/community/people-system/how-to/live-pplsys-howto-nav.md)
- [ハウツー](/ja-jp/services/xbox-services/community/people-system/how-to/index.md)
- [ソーシャル リレーションシップの取得](/ja-jp/services/xbox-services/community/people-system/how-to/live-getting-a-social-relationship.md)
- [製品リレーションシップ管理](/ja-jp/publishing/game-publishing/concepts/relationship-management.md)
- [XblSocialRelationshipChangeEventArgs](/ja-jp/reference/live/xsapi-c/social_c/structs/xblsocialrelationshipchangeeventargs.md)
