首页 > 解决方案 > 如何将 Telegram API 中的 contacts.getLocated() 与 Telethon 一起使用?

问题描述

我想使用 Telegram 的新“附近的人”功能。我想用 python 做,所以我找到了Telethon。然后,我查看了 Telegram API 并找到了contacts.getLocated()方法。 https://core.telegram.org/method/contacts.getLocated

但是我认为 Telethon 库中没有这种方法。或者至少我没有找到如何调用它。

from telethon import functions
functions.contacts.getLocated()

给我: AttributeError: module 'telethon.tl.functions.contacts' has no attribute 'getLocated'

我可以以任何其他方式调用此方法吗?我什至必须为此使用 Telethon 吗?

标签: pythontelethontelegram-api

解决方案


完整 API的Telethon 文档解释了如何使用必须提供的所有原始 Telegram 方法。搜索“定位”我们会找到GetLocatedRequest。有一个复制导入的按钮,底部还有示例代码:

from telethon.sync import TelegramClient
from telethon import functions, types

with TelegramClient(name, api_id, api_hash) as client:
    result = client(functions.contacts.GetLocatedRequest(
        geo_point=types.InputGeoPoint(
            lat=7.13,
            long=7.13
        ),
        self_expires=42
    ))
    print(result.stringify())

不用说,您需要在地理点中传递正确的值。


推荐阅读