Я использую API потоковой передачи твиттера, но не могу получить доступ к атрибуту screen_name
, так как различные уровни вложенности меня немного сбивают с толку
Вот что я пробовал
results = t.search(q='tuberculosis', count=50)
all_tweets = results['statuses']
for tweet in all_tweets:
tweetString = tweet["text"]
name = tweet["entities"]["user_mentions"][0]["screen_name"]
time = tweet["created_at"]
df1['Tweet'] = [tweetString]
df1['Name'] = [name]
df1['Time'] = [time]
df = df.append(df1)
Вот макет JSON:
[
{
"created_at": "Thu Apr 06 15:28:43 +0000 2017",
"id": 850007368138018817,
"id_str": "850007368138018817",
"text": "RT @TwitterDev: 1/ Today we’re sharing our vision for the future of the Twitter API platform!nalink",
"truncated": false,
"entities": {
"hashtags": [],
"symbols": [],
"user_mentions": [
{
"screen_name": "TwitterDev", <------ I want to access this
"name": "TwitterDev",
"id": 2244994945,
"id_str": "2244994945",
"indices": [
3,
14
]
}
],
"urls": [
{
"url": "Link",
"expanded_url": "https://cards.twitter.com/cards/18ce53wgo4h/3xo1c",
"display_url": "cards.twitter.com/cards/18ce53wg…",
"indices": [
94,
117
]
}
]
},
"source": "<a href="http://twitter.com" rel="nofollow">Twitter Web Client</a>",
"in_reply_to_status_id": null,
"in_reply_to_status_id_str": null,
"in_reply_to_user_id": null,
"in_reply_to_user_id_str": null,
"in_reply_to_screen_name": null,
"user": {
"id": 6253282,
"id_str": "6253282",
"name": "Twitter API",
"screen_name": "twitterapi",
"location": "San Francisco, CA",
"description": "The Real Twitter API. I tweet about API changes, service issues and happily answer questions about Twitter and our API. Don't get an answer? It's on my website.",
"url": "Link",
"entities": {
"url": {
"urls": [
{
"url": "Link",
"expanded_url": "https://dev.twitter.com",
"display_url": "dev.twitter.com",
"indices": [
0,
22
]
}
]
},
"description": {
"urls": []
}
},
"protected": false,
"followers_count": 6172353,
"friends_count": 46,......