Skip to content

Instantly share code, notes, and snippets.

@zachmiri
Created September 19, 2019 10:36
Show Gist options
  • Save zachmiri/e45c2c40c3b3f119080e12d4c61d49b1 to your computer and use it in GitHub Desktop.
Save zachmiri/e45c2c40c3b3f119080e12d4c61d49b1 to your computer and use it in GitHub Desktop.
# Update Adset and Campaign Budgets
import requests
import json
import time
# Update with your Facebook Ad Account ID and Access Token
access_token = ''
# Update with a list of IDs and budgets to update
# Note: budgets are multipled by 100 e.g $100 should be 10000 via the API
to_update = [
{
'id': '',
'budget': ''
}
]
for update in to_update:
time.sleep(0.5)
data_dump = {
'daily_budget': update['budget'],
'access_token': access_token
}
r = requests.post('https://graph.facebook.com/v4.0/' + update['id'], data=data_dump)
result = r.json()
if 'success' in result:
print('Successfully updated ID: ' + update['id'])
else:
print('Error updating ID: ' + update['id'] + ', Error: ' + result['error']['message'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment