I used following mastodon python api to get all information of user and I want to access username from it.I explain my input and output below. I am using mastodon.account['username'] to access username but it gives me error.
from mastodon import Mastodon
Mastodon.create_app(
'pytooterapp',
api_base_url = 'https://mastodon.social',
to_file = 'pytooter_clientcred.secret'
)
mastodon = Mastodon(
client_id = 'pytooter_clientcred.secret',
api_base_url = 'https://mastodon.social'
)
mastodon.log_in(
'xyz@gmail.com',
'xyz',
to_file = 'pytooter_usercred.secret'
)
mastodon = Mastodon(
client_id = 'pytooter_clientcred.secret',
access_token = 'pytooter_usercred.secret',
api_base_url = 'https://mastodon.social'
)
I am getting following output when I fire above code in python shell
Output:
{u'account': {u'acct': u'xyz',
u'avatar': u'https://mastodon.social/avatars/original/missing.png',
u'avatar_static': u'https://mastodon.social/avatars/original/missing.png',
u'bot': False,
u'created_at': datetime.datetime(2018, 1, 31, 17, 14, 53, 985000, tzinfo=tzutc()),
u'display_name': u'',
u'emojis': [],
u'fields': [],
u'followers_count': 1,
u'following_count': 3,
u'header': u'https://mastodon.social/headers/original/missing.png',
u'header_static': u'https://mastodon.social/headers/original/missing.png',
u'id': 2871,
u'locked': False,
u'note': u'<p></p>',
u'statuses_count': 6,
u'url': u'https://mastodon.social/@xyz',
u'username': u'xyz'},
u'application': {u'name': u'pytooterapp', u'website': None},
u'content': u'<p>Tooting from python using <a href="https://mastodon.social/tags/mastodonpy" class="mention hashtag" rel="tag">#<span>mastodonpy</span></a> !</p>',
u'created_at': datetime.datetime(2018, 5, 20, 12, 32, 56, 757000, tzinfo=tzutc()),
u'emojis': [],
u'favourited': False,
u'favourites_count': 0,
u'id': 100061647780173,
u'in_reply_to_account_id': None,
u'in_reply_to_id': None,
u'language': u'en',
u'media_attachments': [],
u'mentions': [],
u'muted': False,
u'pinned': False,
u'reblog': None,
u'reblogged': False,
u'reblogs_count': 0,
u'sensitive': False,
u'spoiler_text': u'',
u'tags': [{u'name': u'mastodonpy',
u'url': u'https://mastodon.social/tags/mastodonpy'}],
u'uri': u'https://mastodon.social/users/xyz/statuses/1000616477685173',
u'url': u'https://mastodon.social/@xyz/100061640685173',
u'visibility': u'public'}
Now I want to access 'username' from above dictionary but I am not able to access. When I am trying to access username using "mastodon.account['username']" it gives me following error
"TypeError: 'instancemethod' object has no attribute '__getitem__'"