python - 如何将 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 吗?
解决方案
完整 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())
不用说,您需要在地理点中传递正确的值。
推荐阅读
- sql - 使用 SQL 从一组用户中查找最常见的 varchar
- autodesk-forge - Get the world coordinates of a markup in Forge
- django - Django 查询集可以生成带有自连接的 SQL 语句吗?
- node.js - 如果不存在则创建文档,否则返回 Null 或空:MongoDB
- python - 无法在 iterrows 中检索数据框
- android-studio - Android Studio 识别设备,但无法运行代码
- javascript - iFrame postMessage 和 addEventListener 不起作用
- sql-server - 在 VARCHAR 中选择带有尾随空格 SQL Server 时的未记录功能
- github - 使用 Github Desktop 将代码推送到 github 时出现错误,无法推送一些参考
- r - 通过分隔符解析文本文件并使用 R 输出多个文件