关于How to implement authorization using a Telegram API?这是我找到的最好的电报文件!谢谢你。在
我正在尝试创建一个Python库来调用电报.org. 我可以像上面的链接中描述的那样进行身份验证,但是遇到了方法响应以仅在前一层中找到的格式返回的问题。换句话说,我的客户机正在从api的一个层调用一个方法,但是服务器使用旧api层的数据格式进行响应。我通过搜索旧的api层文件来确认这一点
{
"id": "571849917",
"params": [
{
"name": "phone_registered",
"type": "Bool"
},
{
"name": "phone_code_hash",
"type": "string"
}
],
"predicate": "auth.sentCode",
"type": "auth.SentCode"
},
我的客户期望的格式是:
^{pr2}$所以,我在电报文档中读到我需要调用invokeWithLayer来确保客户机和服务器的api层同步。在
几个问题:
这是我的initConnection代码,在这里我将每个方法序列化,然后将其用作参数。不幸的是,反应并不乐观。第一个反应是:
('initConnection - msg: ', {u'messages': [{u'body': {u'first_msg_id': 6312441942040617984L, u'unique_id': 986871592203578887L, u'server_salt': 7658270006181864880L}, u'seqno': 1, u'msg_id': 6312441944354392065L, u'bytes': 28}, {u'body': {u'msg_ids': [6312441942040617984L]}, u'seqno': 2, u'msg_id': 6312441944354450433L, u'bytes': 20}]})
第二个回应是:
{u'req_msg_id': 6312441942040617984L, u'result': {u'error_message': 'INPUT_METHOD_INVALID', u'error_code': 400}})
…以及代码:
def initConnection(self, config):
'''Set the API layer and initialize the connection'''
# get the required config data
api_layer = config.getint('App data', 'api_layer')
api_id = config.getint('App data', 'api_id')
version = config.get('App data', 'version')
print
print('----------------------------------------------')
print('initConnection - api_layer: ', api_layer)
print('initConnection - api_id: ', api_id)
print('initConnection - version: ', version)
# serialize a candidate method as a parameter. It doesn't
# matter what it is so we will use something simple like get_future_salts.
simpleQuery=TL.tl_serialize_method('get_future_salts', num=3)
# serialize the initConnection method
initConnectionQuery = TL.api_serialize_method('initConnection', api_id=api_id,
device_model='Unknown UserAgent',
system_version='Unknown Platform',
app_version=version,
lang_code='en-US',
query=simpleQuery)
# perform the initialization
msg = self.method_call('invokeWithLayer', layer=api_layer, query=initConnectionQuery)
print('initConnection - msg: ', msg)
谢谢!在
1)我从这里得到最新的电报模式: https://github.com/telegramdesktop/tdesktop/blob/master/Telegram/Resources/scheme.tl
您可以构建自己的TL解析器库,它也可以按照您想要的方式工作,并且可以随着版本的变化轻松地将其更新到最新版本。在
2)要发送X query参数,只需序列化并附加到invoke with layer查询的末尾。在
示例:(来自我的Telegram Elixir库)
您可以看到相关电报模式的定义:
^{pr2}$相关问题 更多 >
编程相关推荐