Hi everyone,
I am new with API Twitter v2 and i try to get conversations data, but i have not good results. My objective is: comments from users, sub-comments, etc. The next figure represent my goal (https://twitter.com/nytimeses/status/1173984627427557376):
My code for the example is:
def make_request_comments(headers,id_conversation):
url = "https://api.twitter.com/2/tweets/search/recent"
query = '(conversation_id:'+str(id_conversation)+')'
query_params = {'query': query,
'expansions': 'geo.place_id,author_id',
'tweet.fields': 'id,text,author_id,in_reply_to_user_id,conversation_id,created_at',
}
return requests.request("GET", url, params=query_params, headers=headers).json()
id_conversation = 1173984627427557376
response = make_request_comments(headers,id_conversation)
response['data']
… und my results are:
[{'author_id': '1406381522073145344',
'in_reply_to_user_id': '2975678883',
'conversation_id': '1173984627427557376',
'id': '1410791239176396801',
'text': '@nytimeses @JorgeGCastaneda Fraude electoral del @JNE_Peru #AuditoriaElectoral https://t.co/waViPMRmjx',
'created_at': '2021-07-02T02:43:37.000Z'},
{'author_id': '1402745602161643520',
'in_reply_to_user_id': '2975678883',
'conversation_id': '1173984627427557376',
'id': '1409712142824001537',
'text': '@nytimeses @JorgeGCastaneda WE NEED HELP FROM YOU THE ELECTIONS IN PERU ARE FRAUDULENT, WE HAVE PROOF. THE CURRENT GOVERNMENT IS CORRUPT, WE DO NOT WANT TO BE COMMUNISTS, WITH AN AUDIT THE TRUTH WILL BE KNOWN. AYUDEN A PERU, COMUNISTAS NUNCA,HAY FRAUDE QUEREMOS AUDITORIA INTERNACIONAL',
'created_at': '2021-06-29T03:15:40.000Z'},
{'author_id': '877348165032099840',
'in_reply_to_user_id': '2975678883',
'conversation_id': '1173984627427557376',
'id': '1409702999304269825',
'text': '@nytimeses @JorgeGCastaneda MÉXICO el único País del mundo donde los niños con cáncer son catalogados como un peligro para dar un golpe de estado.\n#GatellAsesino\n#NinosConCancer \n#NinosGolpistas https://t.co/rQp4VqIA6G',
'created_at': '2021-06-29T02:39:20.000Z'},
{'author_id': '3297909826',
'in_reply_to_user_id': '2975678883',
'conversation_id': '1173984627427557376',
'id': '1409154186734931970',
'text': '@nytimeses @JorgeGCastaneda Mientras haya pandemia por combatir, todos los países están al nivel de la pobreza extrema, sobre todo en materia sanitaria.',
'created_at': '2021-06-27T14:18:33.000Z'}]
I would greatly appreciate your help, I have the following complications:
- I need extract all comments, same in previous picture, in total are 597… I don’t understand, why i have only 4 results?
- I cant extract comments from comments, for built all thread from conversation… what is the best form for this?. The next picture show my objective, however, it could be that that last comment has another associated… the idea is capture all comments relationed.:
I appreciate very much the comments,
Greetings
C.