Hi there,
Below is an implemented Python code to upload Mobile Device Ids through API for remarketing.
But, customer List Id(6534339977) shows its size shows still 0 even though the number of uploaded mobile device Ids is much more than 1,000.
Would there be anyone who can help?
* ATTACHED PYTHON SNIPPET
def send_google_mobile_device_id(df, country_code):
"""Adds a user list and populates it with hashed email addresses.
Note: It may take several hours for the list to be populated with members. Email
addresses must be associated with a Google account. For privacy purposes, the
user list size will show as zero until the list has at least 1000 members. After
that, the size will be rounded to the two most significant digits.
"""
def validate_idfa_format(idfa):
idfa_splited = idfa.split('-')
if [len(ele) for ele in idfa_splited] == [8, 4, 4, 4, 12]:
return True
else:
return False
# CREDENTIAL & AUTHENTICATE, with yaml
gg_config = Config('cro', 'prod', False, True).get_read('googleads')
with open("yaml", "w") as f:
f.write(f"adwords:\n")
f.write(f" developer_token: {gg_config['developer_token']}\n")
f.write(f" client_id: {gg_config['client_id']}\n")
f.write(f" client_secret: {gg_config['client_secret']}\n")
f.write(f" refresh_token: {gg_config['refresh_token']}\n")
f.close()
client = adwords.AdWordsClient.LoadFromStorage('yaml')
today = date.today()
print("As of:", today)
# CREATE A USER LIST
for os in ['AOS', 'iOS']:
user_list = {
'xsi_type': 'CrmBasedUserList',
'name': f'Mobile Device ID({os}) as of {today}_{country_code}',
'description': f'CRO Mobile Device IDs({os})',
'uploadKeyType': 'MOBILE_ADVERTISING_ID',
'appId': cro_app_info[os]
}
# Create an operation to add the user list.
operations = [{
'operator': 'ADD',
'operand': user_list
}]
# Call User List Service
user_list_service = client.GetService('AdwordsUserListService', 'v201809')
result = user_list_service.mutate(operations)
# Organize Mobile Device IDs from files
user_list_id = result['value'][0]['id']
members = [{'mobileId': mobile_id} for mobile_id in df["Mobile Device ID"].tolist() if validate_idfa_format(mobile_id) == True]
# Send User List
n = 0
cut_off = int(4 * 1e5)
for i in range(int(len(members)/cut_off) + 1):
members_split = members[i * cut_off: (i + 1)*cut_off]
n += len(members_split)
# Form into JSON
mutate_members_operation = {
'operand': {
'userListId': user_list_id,
'membersList': members_split
},
'operator': 'ADD'
}
# Upload seeds through API
response = user_list_service.mutateMembers([mutate_members_operation])
if 'userLists' in response:
print(f'a {n} number of User list with name {user_list["name"]} has been added.')