Trouble Accessing Data on Ads API (using PHP)

ads
php

#1

I’ve been trying to access data on a particular account that I have access to via the ADs API but keep getting either “UNAUTHORIZED ACCESS” or “ACTION_NOT_ALLOWED” error messages when I try to make certain calls.

Calls That I’ve Tried so far:
/accounts/ == Works as expected.
/accounts/XXXXXX/promoted_tweets == ACTION_NOT_ALLOWED
/stats/jobs/accounts/XXXXXX?entity=account == UNAUTHORIZED_ACCESS
/stats/accounts/XXXXXX?entity=ORGANIC_TWEET == UNAUTHORIZED_ACCESS

I’m 99.9% sure I have the coding and auth settings correct because it’s working fine with this call:
https://ads-api.twitter.com/4/accounts/
…but not on any of the others listed.

The consumer key, secret, account id, etc are def all correct in the code. The only thing I can think of that I haven’t tried is that the access level of the authenticated user to get this info needs to be higher than an Analyst? Or do we need to regenerate all the keys and secrets again?

Just a little extra background:

  • I see the correct account id that I’m trying to access in the response from the “/accounts/” call.
  • The app information we’re using is from an approved one (for ads api) and our level of access is an Analyst.

Attached are screenshots of the response messages I’m seeing:
adsapi1


#2

Hi @thomasdintrone, as you suspected you will need higher level of access for this account to be able to use the API to pull this data. Some info at the link below:

https://developer.twitter.com/en/docs/ads/general/guides/obtaining-ads-account-access.html


#3

@joncipriano, thanks for the quick response. We upgraded our account and I’m now seeing new information but certain other calls I’m still getting the UNAUTHORIZED_ACCESS Error. Any thoughts?

Example Call:
adsapi4


#4

Hi @thomasdintrone ,

I see you masked your Ads account ID on that screen shot. Providing your Ads account ID here (publicly) is totally safe. Could you tell us your Ads account ID so that we can get more insight for this issue?

Best,
Shohei


#5

Hi @jrsyo, ah ok I wasn’t sure so thought it was a safe bet to leave it out. The account ID is aefe1


#6

@thomasdintrone

Thanks. Please check this post:

Are you encoding your OAuth header strings?
https://developer.twitter.com/en/docs/basics/authentication/guides/percent-encoding-parameters
https://developer.twitter.com/en/docs/basics/authentication/guides/authorizing-a-request

Best,
Shohei


#7

I was able to figure this out using a different twitter library, which one your other developers created I believe (https://github.com/hborras/twitter-php-ads-sdk).

I do have another question though. I was told that there is some organic tweet data available using the Ads API. Can you tell me, or guide me to the developer that created it on how to actually get the organic data from that library?

been trying to figure that part out but I’m hitting a brick wall at the moment. Thanks!


#8

Hi @jrsyo, just wanted to make sure you saw my above comment. Thanks!

@AdsAPI @hector_borras


#9

Hi @thomasdintrone How are you?

Making calls to organic tweet data is not currently available.

I’m working in a new version of the library with this option

Thanks


#10

@hector_borras Thanks appreciate your reply. There may not be built in functions in your library to get it but can you refer me to how I can get that organic info? We really needs this info and perhaps I can customize the library on my own to get it.

I was having trouble finding exactly how in the api docs online.


#11

@thomasdintrone Hi, I’m sorry I missed this topic.

https://developer.twitter.com/en/docs/ads/analytics/api-reference/asynchronous

See above. POST stats/jobs/accounts/:account_id, that is.
You can specify entity= ORGANIC_TWEET in your request parameter. Please note that we normally recommend using asynchronous endpoints to avoid hitting our rate-limit restriction.

https://developer.twitter.com/en/docs/ads/analytics/overview
https://developer.twitter.com/en/docs/ads/analytics/overview/best-practices


#12

@jrsyo, No worries! Ok thanks, I’ll give this a try!


#13

@jrsyo @hector_borras, Thanks again for your help. Ok I think I’m very close to getting this but it’s asking for “entity_ids” as a required parameter. Can you tell me wha those actually are and where do i get that info from?


#14

Hi @thomasdintrone,

Here you haven an example of how do it with TWURL in a syncronous way (not recommended)

twurl -H "https://ads-api.twitter.com" "/4/stats/accounts/ACCOUNTID?entity=ORGANIC_TWEET&start_time=2018-12-13T23:00:00Z&end_time=2018-12-19T23:00:00Z&granularity=TOTAL&placement=ALL_ON_TWITTER&metric_groups=ENGAGEMENT&entity_ids=ENTITY_IDS"  |  jq .

Where ACCOUNTID is the id of your account and ENTITY_IDS are TWEET_IDS separated by commas

Hope this can help you.

Regards