Not Ready: File won't upload when added to Facebook Custom Audience

I am trying to add users to Facebook Custom Audience using version 2.1 of my API.

I am using this Python script to create a new audience and add users to it.

import json, requests

# set up params
account_id = 'an ads account ID'
audience_name = 'a new name'
token = 'a valid access token'

# create a new audience ID for posterity
url =  "https://graph.facebook.com/act_" + account_id + "/customaudiences"
response = requests.post(url, {"name": audience_name, "access_token": token})
resp_dict = json.loads(response.content)
audience_id = resp_dict["id"]

# output new audience name and ID
print("For audience name of:", audience_name)
print("Created audience ID of:", audience_id)

# add email addresses to the audience
the_file = open("the.payload", "r")
payload = the_file.read()
the_file.close()

url = 'https://graph.facebook.com/v2.1/' + audience_id + '/users'
params = {"access_token": token, "payload": payload}
response = requests.post(url, params=params)

# output results
print("Response status code:", response.status_code)
print("Response content:", response.content)

      

Sample "thepayload" content:

{"data":["a8649fb702fb0a67e21ed5120a589cf4d15dd59e2eebb1ad606485731b124100","4842b7883df3c9048abbff1fddb3fd634bed474450f8b2b9102c4bf76fc33381"],"schema":"EMAIL_SHA256"}

      

Except that in my file instead of two valid email addresses that were formatted as SHA256 and written in hex, according to their docs, I have 1100 of them.

When I run this script I get:

('For audience name of:', 'the name I gave')
('Created audience ID of:', u'a valid ID number')
('Response status code:', 200)
('Response content:', '{"audience_id":"a valid ID number","num_received":1100,"num_invalid_entries":0,"invalid_entry_samples":[]}')

      

However, more than an hour later, "Not Ready, File Not Uploaded" is displayed in the user interface for 100% of downloads using this method. enter image description here

Can anyone tell me how to fix my code to successfully add users to custom audiences? I have looked at the Docs in detail, but I believe I am following their format.

+3


source to share


1 answer


This turned out to be a problem with my hashing algorithm.

After posting this question, I got a copy of an email hashing algorithm that has been proven to work. It was like this:

import hashlib
email = "somebody@somewhere.com"
email = email.strip().lower()
email = hashlib.sha256(email).hexdigest()

      



I compared the hash I got here with my own hash and it didn't come out the same way. After fixing it by removing whitespace and reusing hashing in a loop, this issue is resolved.

So, Not Ready can come from a behind-the-scenes hashing issue or download containing too few valid and matching email addresses.

+4


source







All Articles