For the complete documentation index, see llms.txt. This page is also available as Markdown.

概述

关于在 Decentraland 平台中使用 Social Service API 来检索好友关系、请求和共同好友的详细信息。该 API 允许开发者与 Social Service 交互以检索与好友关系相关的信息。

REST API

要检索好友关系,Social Service 提供了 REST API:

  • GET /friendships/me - 检索当前用户的好友关系。需要在 Authorization 头中提供访问令牌。

  • GET /friendships/{other-address}/mutuals - 检索与另一位用户的共同好友。需要在 Authorization 头中提供访问令牌。

WebSocket RPC 服务器

Social Service WebSocket API 提供两种用于检索好友关系和共同好友的消息类型。你需要先建立 WebSocket 连接,然后使用这些方法来流式获取与用户相关的信息。

  • GetFriends - 检索某个用户的好友。返回用户响应流。

  • GetMutualFriends - 检索与另一位用户的共同好友。返回用户响应流。

请参阅 friendships.proto 文件 以了解有关这些消息类型的更多详情。

JavaScript 代码示例

要使用 JavaScript 与 Social Service WebSocket API 交互,你可以像前面说明的那样使用提供的 RPC 客户端。但如果你需要自行实现,下面有一些代码示例,演示如何检索好友和共同好友:

获取所有好友

import { createRpcClient, createWebSocketsTransport } from '@dcl/rpc/dist/client';
import { FriendshipsServiceDefinition } from './protobuff-types/decentraland/social/friendships/friendships.gen';

const socialClientRpcUrl = 'wss://social.decentraland.org'; // 替换为实际 URL
const webSocketsTransport = createWebSocketsTransport(socialClientRpcUrl);
const service = loadService(FriendshipsServiceDefinition, webSocketsTransport);

const response = service.getFriends(Payload.create({ synapseToken }));
for await (const friends of response) {
  processErrors(friends);
  const userList = friends.users?.users ?? [];
  // 处理好友列表
}

获取共同好友

更多代码示例和详细信息,请访问 social-rpc-client-js GitHub 仓库

最后更新于