Last active
August 30, 2024 11:05
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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