0

I want to get week to date list of country names with respective count of followers in that week or date.

Facebook is always giving data of life time.

The code I have used is as follows:

import datetime
# Calculate timestamps for your custom date range
start_date = '2024-06-01'  # Replace with your desired start date
end_date = '2024-06-15'    # Replace with your desired end date

# Convert dates to datetime objects
start_datetime = datetime.datetime.strptime(start_date, '%Y-%m-%d')
end_datetime = datetime.datetime.strptime(end_date, '%Y-%m-%d')

# Calculate timestamps
start_timestamp = int(start_datetime.timestamp())
end_timestamp = int(end_datetime.timestamp())

# Define the endpoint URL
url = f'https://graph.facebook.com/v17.0/{page_id}/insights/page_fans_country/day'

# Specify the access token and the period
params = {
'access_token': access_token,
'since': start_timestamp,
'until': end_timestamp
}

# Make the request to the Graph API
response = requests.get(url, params=params)

# Check if the request was successful
if response.status_code == 200:
 insights_data = response.json()
 # Print the retrieved insights data
 print(json.dumps(insights_data, indent=4))
else:
 print(f"Error: {response.status_code}")
 print(response.json())

How to get this data.

0

Browse other questions tagged or ask your own question.