skip to Main Content

I would like to create and edit pages on Telegram’s telegraph.ph website through telegraph API.

https://telegra.ph/api#createPage

To do so, I need to know the access token of the telegraph account. I’ve been searching high and low using Google how to do it but still can’t find any answer.

I am using telegraph python library.

https://github.com/python273/telegraph

I am using python 3.7

3

Answers


  1. Chosen as BEST ANSWER

    I will answer my own question.

    To add on to Tibebes. M's helpful answer, there seems to be no way to get the access token of an existing Telegraph account. So, the only way is to create the account first, then note down the returned access token. Reuse this access token in future. Otherwise, one will have to create a new account whenever a new Telegraph message is posted. I don't know why Telegraph is designed this way because it will result in many stale accounts but that's just the way it is.


  2. The API endpoint you’re looking for is createAccount. Invoking this endpoint returns an object containing an accesstoken.

    From the docs:

    On success, returns an Account object with the regular fields and an additional access_token field.

    Having said that, the library you’ve mentioned makes it much easier to work with the api. You don’t even to know the access_token explicitly. You only need to call .create_account() and the library will manage the token internally (see here and here to know how).

    Here is a sample code on how to use the lib to create an account and utilize it:

    
    from telegraph import Telegraph
    
    telegraph = Telegraph()
    
    acc = telegraph.create_account(short_name='1337')
    
    print(acc)
    
    response = telegraph.create_page(
        'Hey',
        html_content='<p>Hello, world!</p>',
    
    )
    
    Login or Signup to reply.
  3. There is no available endpoints to obtain actual access_token on Telegraph API.
    But… If you really need to obtain exactly yours Telegraph access_token,
    You can get it by accessing devtools in browser, while authenticated in Telegra.ph via their bot.

    It passed as a cookie tph_token and being sent to check authorization at https://edit.telegra.ph/check endpoint.

    Look at Network tab in your devtools, switch to XHR requests filter, then choose check request (example)

    At the bottom of devtools window, you will see another appeared window, with Headers tab selected.

    Go to Cookies and then you will see your token, that you can use as an access_token

    It’s not an endpoint, by I’m sure, that you can use that instruction to automate obtaining that token, by capturing and parsing some requests, or passing auth url from Telegraph bot expicitly to your python project.
    I don’t know how. Somehow. But sure, that if you want, my answer will help you to create obtaining algorithm

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search