Welcome to Telegraph’s documentation!¶
API¶
-
class
telegraph.api.
Telegraph
(token=None, timeout=5)[source]¶ -
create_account
(short_name, author_name=None, author_url=None, use=True)[source]¶ Use this method to create a new Telegraph account.
See http://telegra.ph/api#getPageList.
Parameters: - short_name – Required. Account name, helps users with several accounts remember which they are currently using. Displayed to the user above the “Edit/Publish” button on Telegra.ph, other users don’t see this name.
- author_name – Default author name used when creating new articles.
- author_url – Default profile link, opened when users click on the author’s name below the title. Can be any link, not necessarily to a Telegram profile or channel.
- use – Whether to set the access token of the current instance to the new account. Default: True
Returns: An Account object.
Return type:
-
create_page
(title: str, content: List[Union[Dict[KT, VT], str]] = None, author_name: str = None, author_url: str = None, return_content: bool = False) → telegraph.types.Page[source]¶ Use this method to create a new Telegraph page.
See http://telegra.ph/api#createPage.
Parameters: - title – Required. Page title.
- content – Required. Content of the page.
- author_name – Author name, displayed below the article’s title.
- author_url – Profile link, opened when users click on the author’s name below the title. Can be any link, not necessarily to a Telegram profile or channel.
- return_content – If true, a content field will be returned in the Page object.
Returns: A Page object.
Return type:
-
edit_account_info
(short_name=None, author_name=None, author_url=None) → telegraph.types.Account[source]¶ Use this method to get information about a Telegraph account.
See http://telegra.ph/api#editAccountInfo.
Parameters: - short_name – New account name.
- author_name – New default author name used when creating new articles.
- author_url – New default profile link, opened when users click on the author’s name below the title. Can be any link, not necessarily to a Telegram profile or channel.
Returns: An Account object.
Return type:
-
edit_page
(path: str, title: str, content: List[Union[Dict[KT, VT], str]], author_name: str = None, author_url: str = None, return_content: bool = False) → telegraph.types.Page[source]¶ Use this method to edit an existing Telegraph page.
See http://telegra.ph/api#editPage.
Parameters: - path – Required. Path to the page.
- title – Required. Page title.
- content – Required. Content of the page.
- author_name – Author name, displayed below the article’s title.
- author_url – Profile link, opened when users click on the author’s name below the title. Can be any link, not necessarily to a Telegram profile or channel.
- return_content – If true, a content field will be returned in the Page object.
Returns: A Page object.
Return type:
-
get_account_info
(fields: List[str] = None) → telegraph.types.Account[source]¶ Use this method to get information about a Telegraph account.
See http://telegra.ph/api#editAccountInfo.
Parameters: fields – List of account fields to return. Available fields: short_name
,author_name
,author_url
,auth_url
,page_count
. Default is["short_name", "author_name", "author_url"]
.Returns: An Account object. Return type: Account
-
get_page
(path: str, return_content=False) → telegraph.types.Page[source]¶ Use this method to get a Telegraph page.
See http://telegra.ph/api#getPage.
Parameters: - path – Required. Path to the Telegraph page (in the format Title-12-31,
i.e. everything that comes after
http://telegra.ph/
). - return_content – If true, content field will be returned in Page object. Default is
False
.
Returns: A Page object.
Return type: - path – Required. Path to the Telegraph page (in the format Title-12-31,
i.e. everything that comes after
-
get_page_list
(offset: int = 0, limit: int = 50)[source]¶ Use this method to get a list of pages belonging to a Telegraph account.
See http://telegra.ph/api#getPageList.
Parameters: - offset – Sequential number of the first page to be returned. Default is 0.
- limit – Limits the number of pages to be retrieved. Default is 50.
Returns: A PageList object.
Return type:
-
get_views
(path: str, year: int = None, month: int = None, day: int = None, hour: int = None) → telegraph.types.PageViews[source]¶ Use this method to get the number of views for a Telegraph article.
See http://telegra.ph/api#getViews.
Parameters: - path – Required. Path to the Telegraph page
(in the format
Title-12-31
, where 12 is the month and 31 the day the article was first published). - year – Required if month is passed. If passed, the number of page views for the requested year will be returned.
- month – Required if day is passed. If passed, the number of page views for the requested month will be returned.
- day – Required if hour is passed. If passed, the number of page views for the requested day will be returned.
- hour – If passed, the number of page views for the requested hour will be returned.
Returns: A PageViews object.
Return type: - path – Required. Path to the Telegraph page
(in the format
-
revoke_access_token
() → telegraph.types.Account[source]¶ - Use this method to revoke access_token and generate a new one, for example,
- if the user would like to reset all connected sessions, or you have reasons to believe the token was compromised.
See http://telegra.ph/api#revokeAccessToken.
Returns: An Account object with new access_token
andauth_url
fields.Return type: Account
-
Types¶
-
class
telegraph.types.
Account
(short_name, author_name, author_url, access_token, auth_url, page_count)[source]¶ -
access_token
¶ Alias for field number 3
-
auth_url
¶ Alias for field number 4
Alias for field number 1
Alias for field number 2
-
page_count
¶ Alias for field number 5
-
short_name
¶ Alias for field number 0
-
-
class
telegraph.types.
Page
(path, url, title, description, views, author_name, author_url, image_url, content, can_edit)[source]¶ Alias for field number 5
Alias for field number 6
-
can_edit
¶ Alias for field number 9
-
content
¶ Alias for field number 8
-
description
¶ Alias for field number 3
-
image_url
¶ Alias for field number 7
-
path
¶ Alias for field number 0
-
title
¶ Alias for field number 2
-
url
¶ Alias for field number 1
-
views
¶ Alias for field number 4