how to get the access_hash from channel_id in tele

2019-05-05 17:32发布

问题:

I have a program developed by Tlsharp and I want joining channel that I have its channel_id, but for joining channels I need channel_id and access_hash for TLRequestJoinChannel request.

So I need to get access_hash from channel_id.

Can anybody help me to solve this problem?

回答1:

this code works 100% :-)

var channelInfo = (await client.SendRequestAsync<TeleSharp.TL.Contacts.TLResolvedPeer>(
new TeleSharp.TL.Contacts.TLRequestResolveUsername
{
    username = "ChannelID"
}).ConfigureAwait(false)).chats.lists[0] as TeleSharp.TL.TLChannel;

var Request = new TeleSharp.TL.Channels.TLRequestJoinChannel()
{
    channel = new TLInputChannel
    {
        channel_id = channelInfo.id,
        access_hash = (long) channelInfo.access_hash
    }
};

try
{
    var Respons = await client.SendRequestAsync<Boolean>(Request);
}
catch (exception ex)
{
    // Do stuff
}


回答2:

   var dialogs = (TLDialogs) await client.GetUserDialogsAsync();

        var channel = dialogs.chats.lists
            .OfType<TLChannel>()
            .FirstOrDefault(c => c.title == "channelName");

             long access_hash = (long) channel.access_hash;


标签: c# api telegram