Uploading data to a Custom dimension META

17 views Asked by At

I'm trying to upload data to a Custom Dimension of META through a Python Script. The amount of data I've got is aboyt 252.000 rows, so I've got to use a batch of 10.000 as Meta says. The problem is that when I go to adsmanager I onli see that the amount of rows uploaded is the same as the size of the last batch (in my case 678 rows. Here is the code I'm using, the data comes from a Bigquery table, only email hashed:

def main():
    hashed_emails = export_table_to_csv()
    hashed_emails = hashed_emails[:9000]
    access_token = '+++++++++++'
    app_secret = '++++++++++'
    app_id = '++++++++++++'
    audience_id = '++++++++++++++'
    FacebookAdsApi.init(app_id, app_secret, access_token)

    batch_size = 9550
    hashed_emails_batches = [hashed_emails[i:i + batch_size] for i in range(0, len(hashed_emails), batch_size)]

    for i, batch in enumerate(hashed_emails_batches):
        email_hashes = [str(item.get('email_hashed', '')) for item in batch] 
        session_params = {
            "session_id": i + 1,
            "batch_seq": i + 1,
            "last_batch_flag": i == len(hashed_emails_batches) - 1,
            "estimated_num_total": len(hashed_emails)
        }
        print(f"Starting with: {session_params}")
        sample_size = min(5, len(email_hashes)) 
        print(f"Sample of email_hashes in batch: {email_hashes[:sample_size]}")
        print(f"Batch dimension: {len(email_hashes)}")
        custom_audience = CustomAudience(audience_id)
        custom_audience.add_users(CustomAudience.Schema.email_hash, email_hashes, session=session_params)
        print(f"Finished with: {session_params}")

I tried to do it without batch, limiting tha data to 5000 and uploading it just in one time, and then in adsmanager I get that 18000 rows were added, I don't understand anything.

0

There are 0 answers