Skip to content

Instantly share code, notes, and snippets.

@alecbw
Last active August 30, 2024 11:05
Show Gist options
  • Save alecbw/3e63233d31f9135a57916ca00a3e9d3b to your computer and use it in GitHub Desktop.
Save alecbw/3e63233d31f9135a57916ca00a3e9d3b to your computer and use it in GitHub Desktop.
Find Facebook Interest Targeting options via API, single query (adinterestsuggestion supports passing a list, but this implementation does not consider that)
import os
import requests
def query_ad_interest_api(query, api_type):
query_url = "https://graph.facebook.com/v9.0/search?locale=en_US&limit=1000"
query_url += '&access_token=' + os.environ['FB_ACCESS_TOKEN']
if api_type.title() == "Suggestion":
query_url += '&type=adinterestsuggestion&interest_list=["' + str(query.title()) + '"]'
elif api_type.title() == "Search":
query_url += '&type=adinterest&q=' + str(query)
response = requests.get(query_url)
return response.json(), response.status_code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment