---
title: "インタラクションを得て"
slug: "get-interactions"
abstract: "相互作用または相互作用の集合をどう取得するか。"
---
# インタラクションを得て

.GetAsync<Interaction>() / .Get<Interaction>() を使って相互作用または相互作用の集合を取得します。相互作用は以下で取得できます:

-   インタラクションIDとコンタクトIDの組み合わせ
-   インタラクションIDとコンタクト参照の組み合わせ

> !注コンタクトIDまたはコンタクトリファレンスは、シャード環境でのクエリ効率を高めるために含まれています。コレクションデータはコンタクトID上でシャード化されるため、クエリにコンタクトIDを含めることで、xConnectはどのシャードがインタラクションデータを保持しているかを即座に把握できます。

次の例では、2つの相互作用が引き出されます。

using Sitecore.XConnect;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Collections.ObjectModel;
using Sitecore.XConnect.Operations;
using Sitecore.XConnect.Client;

namespace Documentation
{
 public class GetInteractions
 {
 // Async interaction
 public async void ExampleAsync()
 {
 using (Sitecore.XConnect.Client.XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient())
 {
 try
 {

 var interactionIdOne = Guid.Parse("DA2DA5F0-4348-E611-82E7-34E6D7117DCB");
 var interactionIdTwo = Guid.Parse("B9814105-1F45-E611-82E6-34E6D7117DCB");

 // Contact reference from ID
 var contactRef = new ContactReference(interactionIdOne);
 Sitecore.XConnect.InteractionReference interactionRef = new Sitecore.XConnect.InteractionReference(contactRef, interactionIdTwo);

 // Contact reference from identifier
 var identifiedContactRef = new IdentifiedContactReference("twitter", "myrtlesitecore");
 Sitecore.XConnect.InteractionReference secondInteractionRef = new Sitecore.XConnect.InteractionReference(identifiedContactRef, Guid.Parse("E6067926-1F45-E611-82E6-34E6D7117DCB"));

 var references = new List<Sitecore.XConnect.InteractionReference>()
 {
 interactionRef, secondInteractionRef
 };

 Task<ReadOnlyCollection<IEntityLookupResult<Interaction>>> interactionTask = client.GetAsync<Sitecore.XConnect.Interaction>(references, new InteractionExecutionOptions(new InteractionExpandOptions() { }));

 ReadOnlyCollection<IEntityLookupResult<Interaction>> interaction = await interactionTask;
 }
 catch (Exception ex)
 {
 // Manage exceptions
 }
 }
 }

 // Sync example
 public async void ExampleSync()
 {
 using (Sitecore.XConnect.Client.XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient())
 {
 try
 {

 var interactionIdOne = Guid.Parse("DA2DA5F0-4348-E611-82E7-34E6D7117DCB");
 var interactionIdTwo = Guid.Parse({B9814105-1F45-E611-82E6-34E6D7117DCB});

 // Contact reference from ID
 var contactRef = new ContactReference(interactionIdOne);
 Sitecore.XConnect.InteractionReference interactionRef = new Sitecore.XConnect.InteractionReference(contactRef, interactionIdTwo);

 // Contact reference from identifier
 var identifiedContactRef = new IdentifiedContactReference("twitter", "myrtlesitecore");
 Sitecore.XConnect.InteractionReference secondInteractionRef = new Sitecore.XConnect.InteractionReference(identifiedContactRef, Guid.Parse("E6067926-1F45-E611-82E6-34E6D7117DCB"));

 var references = new List<Sitecore.XConnect.InteractionReference>()
 {
 interactionRef, secondInteractionRef
 };

 IReadOnlyCollection<IEntityLookupResult<Interaction>> interactions = client.Get<Interaction>(references, new InteractionExecutionOptions(new InteractionExpandOptions() { }));
 }
 catch (Exception ex)
 {
 // Manage exceptions
 }
 }
 }
 }
}

インタラクションのリストを要求する場合、返還タイプはコンタクトのリストではなく**操作結果**のリストとなります。返還タイプはReadOnlyCollection<IEntityLookupResult<Contact>>です。このコレクションをループする際、各EntityLookupResult<Interaction>オブジェクトのEntityプロパティを通じてInteractionオブジェクト自体にアクセスできます。推奨される方法は、Interactionがnullかどうか、またはエンティティがExistsかどうかを確認することです。関連する操作結果の対応Exceptionも利用可能です。

シングルコンタクトの場合は .GetContactAsync() 方式を使えます。複数のコンタクトが入る場合は、.GetAsync<Contact>() の方が性能が良いので使うのが良いです。

## インタラクションイベントを取得

インタラクションは常に利用可能なすべてのイベントで再利用されます。さまざまなイベントの対応については「 [インタラクションイベントの取得](https://doc.sitecore.com/xp/ja/developers/93/sitecore-experience-platform/get-interaction-events.html "Get interaction events") 」を参照してください。

## 交流や関連連絡の機会を得る

デフォルトでは、インタラクションはファセットや関連する連絡先なしで返されます。展開オプションを使って、どのファセットや連絡先情報を返すべきかを判断します:

-   [インタラクションの側面を得てください](https://doc.sitecore.com/xp/ja/developers/93/sitecore-experience-platform/get-interaction-facets.html "Get interaction facets")
-   [関連連絡先を拡大](https://doc.sitecore.com/xp/ja/developers/93/sitecore-experience-platform/expand-related-contact.html "Expand related contact")