ソーシャルな関係を取得する
注意
このトピックでは、API の詳細な使用方法を示します。 Social Manager でサポートされていないシナリオが見つかった場合は、担当の開発者アカウント マネージャー (DAM) までご連絡ください。
このトピックでは、Social Manager API を使用してユーザーのソーシャル関係とそのパブリック プロパティを取得する方法を示すコード例を示します。
Social Manager の使用を開始するには、「Social Manager の概要」を参照してください。 Social Manager API は、フレンド登録とゲーム プレイ状況の追跡を大幅に簡素化します。
最初のユーザーのソーシャル関係を取得する
次のコード例は、Xbox サービスでソーシャル関係を取得する方法を示します。
次のコード例では、以下の操作を実行します。
- システム上のすべてのユーザーのリストを生成し、最初のユーザーを取得します。
- ユーザーのソーシャル関係のすべてを取得します。
- これらの各関係のパブリック プロパティを表示します。
フラット C API
auto asyncBlock = std::make_unique<XAsyncBlock>();
asyncBlock->queue = queue;
asyncBlock->context = nullptr;
asyncBlock->callback = [](XAsyncBlock* asyncBlock)
{
std::unique_ptr<XAsyncBlock> asyncBlockPtr{ asyncBlock }; // Take over ownership of XAsyncBlock*.
HRESULT hr = XblSocialGetSocialRelationshipsResult(asyncBlock, &state.socialResultHandle);
// Be sure to call XblSocialRelationshipResultCloseHandle when the result object is no longer needed.
};
HRESULT hr = XblSocialGetSocialRelationshipsAsync(
xboxLiveContext,
xboxUserId,
socialRelationshipFilter,
0,
0,
asyncBlock.get()
);
if (SUCCEEDED(hr))
{
// The call succeeded, so release the std::unique_ptr ownership of XAsyncBlock* because the callback will take over ownership.
// If the call fails, std::unique_ptr will keep ownership and delete XAsyncBlock*.
asyncBlock.release();
}
詳細については、以下を参照してください。
- XAsyncBlock
- XblSocialGetSocialRelationshipsAsync
- XblSocialGetSocialRelationshipsResult
- XblSocialRelationshipResultCloseHandle
単一の関係を取得する
フラット C API
const XblSocialRelationship* relationships = nullptr;
size_t relationshipsCount = 0;
HRESULT hr = XblSocialRelationshipResultGetRelationships(state.socialResultHandle, &relationships, &relationshipsCount);
LogToFile("Got %u SocialRelationships:", relationshipsCount);
for (size_t i = 0; i < relationshipsCount; ++i)
{
LogToFile("Xuid = %u, isFollowingCaller = %u", relationships[i].xboxUserId, relationships[i].isFollowingCaller);
}
詳細については、以下を参照してください。
関係の次のページを取得する
フラット C API
bool hasNext{ false };
HRESULT hr = XblSocialRelationshipResultHasNext(state.socialResultHandle, &hasNext);
if (hasNext)
{
auto asyncBlock = std::make_unique<XAsyncBlock>();
asyncBlock->queue = queue;
asyncBlock->context = nullptr;
asyncBlock->callback = [](XAsyncBlock* asyncBlock)
{
std::unique_ptr<XAsyncBlock> asyncBlockPtr{ asyncBlock }; // Take over ownership of XAsyncBlock*.
// Close the handle to the previous page of results.
if (state.socialResultHandle)
{
XblSocialRelationshipResultCloseHandle(state.socialResultHandle);
}
HRESULT hr = XblSocialRelationshipResultGetNextResult(asyncBlock, &state.socialResultHandle);
};
uint32_t maxItems = 100;
HRESULT hr = XblSocialRelationshipResultGetNextAsync(xboxLiveContext, state.socialResultHandle, maxItems, asyncBlock.get());
if (SUCCEEDED(hr))
{
// The call succeeded, so release the std::unique_ptr ownership of XAsyncBlock* because the callback will take over ownership.
// If the call fails, std::unique_ptr will keep ownership and delete XAsyncBlock*.
asyncBlock.release();
}
}
詳細については、以下を参照してください。