Audience Upload via Ads API



Is it possible to upload a encrypted audience list(email) via ads API?

how to create audience via ads API?

how to target the same via AP?

Kindly let us know.


Hi @Vinoth! Please see for creating a tailored audience, and then you need to target its users by adding the audience id to the targeting options of the line item: - the field tailored_audiences.
(The line item belongs to a campaign, so you need to create a campaign too.)


Hi @majoritasdev,

Thanks for the response as well as the steps.

i understood from the first link, we have to

  1. hash the data
  2. Upload the data using TON API
  3. Create place holder for tailor audience
  4. Using tailor_audience_change, we can add or delete the audience.

i have seen code samples are available on ruby, perl for TON API. Is it anything available for java?

Kindly let me know.

Note: I have done 1, 3, and 4.



Hi @Vinoth. I don’t know about Java, I use PHP. But all you need to do is make a POST request to, sending the headers Content-Type, and X-TON-Expires in the RFC 2822 format (e.g.: Thu, 21 Dec 2000 16:01:07 +0200), and the hashed data as the raw post body, and from the response get the value of the Location header.


Hi @majoritasdev,

It works. Able to get the location values

I have set content-type as text/plain, X-TON-Expires as tomw date in the format of RFC 2822 also set the Authorization header which makes to work.

Thanks much.


:thumbsup: Great! :slight_smile: You’re welcome!


Hi @majoritasdev,

I have one clarification regarding authentication and authorization for API Call. Please clarify

For every API call, we need consumer key, consumer secret, access token and secret token.

I have my consumer key and consumer secret. Using that am calling “” this api and get response like both secret token and access token.

Now when i use these access token and secret token for other API calls like create campaign etc… getting “401:Authorization Required”

Am i missing anything here?

Actually, we have to create a campaign on behalf of my merchant where merchant will share consumer key and consumer secret alone with us. That’s why trying this approach to get the token’s



Please see for guidance about retrieving OAuth tokens from advertisers. I highly recommend to test your scenario using twurl because you can see the process of obtaining access and storing the tokens in local .twurlrc file and then try to replicate that in code.




Hi @JBabichJapan,

Thanks for the response.

i would like to create a campaign on behalf of some one who shares only consumer keys. Using that i have to get tokens then do the necessary ads API call.

Note, this will not involve any intermediate browser signin or redirect.

Kindly let me know is it possible via only API calls. if so, let me know the APIs.



Hi @Vinoth. That is not possible. The user has to authorize your application for you to be able to do that on his/her behalf. You cannot do anything on behalf of someone else is (s)he doesn’t specifically give you permission to do so.


Hi @majoritasdev,

Thanks for the reply.

is this one time authorize?

I guess, Pin based auth will work for us. i will have a look on it and get back to you in case of clarification.



Yes, this is one time auth. Well, unless the user revokes access of your app, in which case you would need to re-request permission from the user.


Hi @majoritasdev,


It works. Able to call other Ads API’s using Advertisers Access and Secret Token.

Step involved:
Step #1: Obtaining a request token
API Call : POST oauth/request_token

Step #2: Redirecting the user
API Call : GET oauth/authenticate – Passed the oauth_token which i got from Step1

Step #3: Converting the request token to an access token
API Call : POST oauth/access_token – Sent both PIN(from the response of Step 2) and oauth_token(From the response of Step 1)

Now i able to call Ads api with my consumer key along with tokens(From the response of step 3)


Thanks much.


You’re welcome, @Vinoth! I’m glad it works! :slight_smile:


Hi @majoritasdev,

I have a small clarification. Pls clarify

Am a ads developer and i able to create campaign for advertiser, but this campaign is not reflected on advertiser ads account instead of it is displaying in my account.

Is this a right behavior or am i missing anything here?



It is displaying on your ads account instead of the advertiser’s? Well:
1) you must use the advertiser’s account number
2) the advertiser (his/her twitter account to which the ads account belongs to) must authorize your app which you’re using to interact with the Ads API.


Hi @majoritasdev,

Thanks for the response. Its working.



Hi @majoritasdev,

Am getting “[{“code”:“SERVICE_UNAVAILABLE”,“message”:“Service unavailable due to request timeout; please try the request again later”}]” from twitter sandbox server for all my api calls.

is that twitter sandbox server down? is so how to check? where to inform?

Kindly help me on this.



Hi @Vinoth! Yes, it’s possible that the sandbox was down. Do you receive this error for 100% of your calls? Have you retried your calls after a period of time to see if you still get this error?


Hi @majoritasdev,

Thanks for the response

From early morning 2’c clk to till now am getting this error.

Yes, for all my API’s call, am getting this error.

Is that anything related to account lock? i have tried with different ads account and getting the same issue.