Creating a Tailored Audience using Java Ads API SDK


Hi All,

I am not able to implement the Tailored Audience Creation using the java ads api sdk. Could you please help me in the right direction.

I have all the 4 tokens and account id, but when i am creating my own class and referncing the , i am not getting some of the instances.

I simply need to create a tailored audience and upload data file using java ads api sdk.



cc: @abhishek_pyro


Please help me, it’s urgent.

Thanks in advance.


Hey, what version are you using of Twitter4j-ads?



I have implemented it . I am using the Tailored Audience Implementation.
I am calling the createTailoredAudience method with accountID,Audience Name and Tailored Audience Type EMAIL. It is returning an object of BaseAdsResponse of TailoredAudience.

I can see that the Tailored Audience is getting created but it is hsowing processing since long time.

When i print the object of BaseAdsResponse, it shows null.

Please help


@abhishek_pyro Could you please help me urgently with the steps to create tailored audience.



I am using this.

BaseAdsResponse ta = audienceApi.createTailoredAudience(accountID,“Test21”, TailoredAudienceDataType.EMAIL);

but ta object gives null.

Thanks in advance for the help.


Hi @kingams16 this function corresponds to which creates the audience shell and then you add file to it later with the tailored_audience_changes endpoint.

I’m not sure why the object is returning null but I just ran some code calling the same line of code and I now see the tailored_audience in my account hitting it with twurl. I would recommend using the SDK and twurl in parallel as it will be easier for you to double check that things are being created correctly.


could you please send me some sample line of code that will help me for creating tailored audience using java sdk.

Regards and thanks

    TwitterAds twitterAdsInstance = getTwitterAdsInstance();
    TwitterAdsAudienceApi audienceApi = twitterAdsInstance.getTailoredAudienceApi();
    try {
        BaseAdsResponse ta = audienceApi.createTailoredAudience("<insert your account ID here>", "Test", TailoredAudienceDataType.EMAIL);
    } catch (TwitterException e) {

This is with the 1.1 version of JAR, I would recommend starting with the samples from Examples and play around with those. The team is aware of some compilation issues with code as it is on GitHub - thanks for working around those in the meantime.


@JBabichJapan , @abhishek_pyro

The audience is getting created in the twitter ads account. But the response object is still displaying null. Could you please help.



@JBabichJapan Please help me why the
TwitterTonUploadResponse upR = audienceApi.uploadTailoredAudience(file);
is returning null even when i can see the audience in the twitter ads account.

Please help me urgently since one of my important work is stucked.

Regards and thanks in advance for help.


Hi @JBabichJapan and team,

Could you please clear my confusion.

Let’s say the data file have 3 columns let say name,phone , email.
Column 1 Column 2 Column 3
Name Phone Email

Then if i upload it through sdk code and audience type is EMAIL (TailoredAudienceDataType.EMAIL) , then the uploaded audience will have email or email along with other details as well.

Help me with the BaseAdsResponse ta = audienceApi.createTailoredAudience("", “Test”, TailoredAudienceDataType.EMAIL); as well i am stucked.

Please help.


Hi @JBabichJapan , @abhishek_pyro Please help me with this issue.

Also could you please let me know when i am creating the tailored audience from java code and uploading the file , do i need to write any line of code for hashing the file.

It will be better if you provide code for the complete functionality of creating tailored audience and uploading the data file including hashing.

Regards and thanks in advance for help.


Hashing needs to be done before uploading

        return org.apache.commons.codec.digest.DigestUtils.sha256Hex(txt);```

TwitterTonUploadResponse object returning null

A Ton file (file uploaded on Ton) could have only one type of data for one operation.

Please refer the docs, the docs clarify this point in details


Thanks @abhishek_pyro for the details , could you please provide me a complete set of code for example so that i can undertand even better for creating a tailored audience and uploading the data file alngwith hashing.

Thanks a lot in advance for help.


Unfortunately the only sample code readily available are those under - we are welcome to contributions if you figure it out before someone can add one there.

For the data upload part there are samples available for scripting languages like: if you just need to upload files programmatically you could script using that with commands like ./ton_upload -m upload -b ta_partner -f ~/my_data.txt but this would simply be a workaround available for you.


@JBabichJapan and @abhishek_pyro and team

Please give me the set of code for hashing the data file before uploading to tailored audience. that will be great.



@JBabichJapan , @abhishek_pyro

It will be great if you can help me with the 2-3 lines of code for uploading the data file after hashing to the tailored audience.