0
# Account Management
1
2
Telegraph account operations for creating, managing, and configuring Telegraph accounts. All account methods are available in both synchronous and asynchronous versions.
3
4
## Capabilities
5
6
### Create Account
7
8
Create a new Telegraph account with custom configuration.
9
10
```python { .api }
11
def create_account(short_name: str, author_name: str = None, author_url: str = None, replace_token: bool = True) -> dict:
12
"""
13
Create a new Telegraph account.
14
15
Parameters:
16
- short_name (str): Account name displayed to user above Edit/Publish button
17
- author_name (str, optional): Default author name for new articles
18
- author_url (str, optional): Default profile link for author name
19
- replace_token (bool): Whether to replace current token with new account token
20
21
Returns:
22
dict: Account information including access_token and auth_url
23
"""
24
```
25
26
Usage example:
27
28
```python
29
from telegraph import Telegraph
30
31
telegraph = Telegraph()
32
response = telegraph.create_account(
33
short_name='my-blog',
34
author_name='Jane Doe',
35
author_url='https://janedoe.com'
36
)
37
print(f"Access token: {response['access_token']}")
38
print(f"Auth URL: {response['auth_url']}")
39
```
40
41
### Edit Account Information
42
43
Update existing account information. Only provide parameters you want to change.
44
45
```python { .api }
46
def edit_account_info(short_name: str = None, author_name: str = None, author_url: str = None) -> dict:
47
"""
48
Update Telegraph account information.
49
50
Parameters:
51
- short_name (str, optional): New account name
52
- author_name (str, optional): New default author name
53
- author_url (str, optional): New default profile link
54
55
Returns:
56
dict: Updated account information
57
"""
58
```
59
60
Usage example:
61
62
```python
63
telegraph = Telegraph(access_token='your_token')
64
response = telegraph.edit_account_info(
65
author_name='Jane Smith',
66
author_url='https://janesmith.com'
67
)
68
```
69
70
### Get Account Information
71
72
Retrieve current account information and statistics.
73
74
```python { .api }
75
def get_account_info(fields: list = None) -> dict:
76
"""
77
Get Telegraph account information.
78
79
Parameters:
80
- fields (list, optional): Specific fields to return. Available fields:
81
'short_name', 'author_name', 'author_url', 'auth_url', 'page_count'
82
Default: ['short_name', 'author_name', 'author_url']
83
84
Returns:
85
dict: Account information with requested fields
86
"""
87
```
88
89
Usage example:
90
91
```python
92
telegraph = Telegraph(access_token='your_token')
93
94
# Get default fields
95
info = telegraph.get_account_info()
96
97
# Get all available fields
98
full_info = telegraph.get_account_info([
99
'short_name', 'author_name', 'author_url', 'auth_url', 'page_count'
100
])
101
print(f"Total pages: {full_info['page_count']}")
102
```
103
104
### Access Token Management
105
106
Manage account access tokens for authentication.
107
108
```python { .api }
109
def get_access_token() -> str:
110
"""
111
Get current access token.
112
113
Returns:
114
str: Current access token or None if not set
115
"""
116
117
def revoke_access_token() -> dict:
118
"""
119
Revoke current access token and generate a new one.
120
121
Returns:
122
dict: New access_token and auth_url
123
"""
124
```
125
126
Usage example:
127
128
```python
129
telegraph = Telegraph(access_token='old_token')
130
131
# Check current token
132
current_token = telegraph.get_access_token()
133
134
# Revoke and get new token
135
response = telegraph.revoke_access_token()
136
new_token = response['access_token']
137
print(f"New token: {new_token}")
138
```
139
140
## Error Handling
141
142
Account operations may raise the following exceptions:
143
144
- `TelegraphException`: General API errors (invalid parameters, API failures)
145
- `RetryAfterError`: Rate limiting errors with retry_after seconds
146
147
```python
148
from telegraph import Telegraph
149
from telegraph.exceptions import TelegraphException, RetryAfterError
150
151
telegraph = Telegraph()
152
153
try:
154
response = telegraph.create_account(short_name='test')
155
except RetryAfterError as e:
156
print(f"Rate limited. Retry after {e.retry_after} seconds")
157
except TelegraphException as e:
158
print(f"API error: {e}")
159
```