Hi running the below code (with my app key) and it does not seem to working is there anything obvious I am doing wrong?
import requests
import json
import pandas as pd
# Set up authentication headers
headers = {
'Authorization': 'APPKEY',
'Content-Type': 'application/json'
}
# Define search criteria
search_term = 'Rolls-Royce'
start_date = '2022-04-24T00:00:00Z'
end_date = '2022-05-01T23:59:59Z'
# Define endpoint and query parameters
endpoint = 'https://api.refinitiv.com/data/news/v1/articles'
params = {
'query': search_term,
'startTime': start_date,
'endTime': end_date,
'language': 'en',
'count': 100,
'includeSentiment': True
}
# Make request and get response
response = requests.get(endpoint, headers=headers, params=params)
# Convert response to JSON
data = json.loads(response.text)
# Extract sentiment information and aggregate by day
df = pd.DataFrame(data['data'])
df['publishedDate'] = pd.to_datetime(df['publishedDate'], format='%Y-%m-%dT%H:%M:%SZ')
df['sentiment'] = df['sentiment'].apply(lambda x: x['score'])
df = df.groupby(pd.Grouper(key='publishedDate', freq='D'))['sentiment'].mean().reset_index()
# Print result
print(df)