如何使用Telethon获取转发邮件的频道/聊天/用户名?

时间:2017-10-13 12:25:51

标签: python python-3.x telegram telethon

我尝试按频道ID获取频道名称:

result = self._client(GetHistoryRequest(
        entity,
        limit=100,
        offset_date=None,
        offset_id=0,
        max_id=0,
        min_id=last_read_message_id,
        add_offset=0
    ))
for message in result.messages:
    if isinstance(message.fwd_from, MessageFwdHeader):
        fwd_channel_id = message.fwd_from.channel_id
        if fwd_channel_id:
            fwd_result = self._client(GetFullChannelRequest( # problem!!!
                InputPeerChannel(message.fwd_from.channel_id, 0)
            ))

message.fwd_from看起来像:

fwd_from=MessageFwdHeader(
  channel_id=1053596007, 
  date=datetime.fromtimestamp(1507891987.0), 
  post_author=None, # None!!!
  from_id=None, 
  channel_post=3030
), 

所以,我不能从message.fwd_from获取频道名称。我不加入这个频道。

当我尝试拨打GetFullChannelRequest时,我有下一个错误:

  

ChannelInvalidError(...),'无效的频道对象。一定要通过   正确的类型,例如确保请求是设计的   对于频道或以其他方式寻找更适合的频道。'

如何正确获取频道名称?

1 个答案:

答案 0 :(得分:0)

回答here

示例:

public void onCreate(Bundle savedInstanceState) {
    ...
    firstListView.setOnItemClickListener(new Android.widget.AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // Add new items based on clicked position to your second ListView
        })
    ...
}