Not able to access twitter API



We have an application built which uses the twitter Ads API to extract ad-set level data. Till recent times it was working just fine but we are getting the following error now:
2016-09-22 11:52:06,367 INFO interim DblClick file uploaded to the table
2016-09-26 12:08:27,934 ERROR Not able to access Twitter
> Traceback (most recent call last):
> File “C:\Users\dhinesh.baulraj\Desktop\Paul\DMD\Twitter\twitter_prod (1).py”, line 110, in
> account = client.accounts(ACCOUNT_ID)
> File “C:\Python27\lib\site-packages\twitter_ads\”, line 89, in accounts
> return Account.load(self, id) if id else Account.all(self)
> File “C:\Python27\lib\site-packages\twitter_ads\”, line 46, in load
> response = Request(client, ‘get’, resource, params=kwargs).perform()
> File “C:\Python27\lib\site-packages\twitter_ads\”, line 59, in perform
> raise Error.from_response(response)
> Forbidden

The following are the things that we checked:

  • The access to the account is available
  • Individual accounts under the main account have access too


@ami_Debapam: What endpoint are you trying to reach? Could you please provide the request and response bodies, preferably using twurl? This’ll help us narrow down the issue.


@juanshishido: We are pulling data first at account level and then campaign level. So one parent account has access to multiple Twitter Ad accounts.

Request at account level:
resource = ‘/0/accounts/’.format(
response = Request(client, ‘get’, resource, params=params).perform()

params is empty till this level.

We then iterate through the accounts extracted and extract data from all campaigns inside each acccount.

Request at Campaign Level:
resource = ‘/0/stats/accounts/{accid}/campaigns/{campid}’.format(accid=row[‘account_id’] ,campid=row[‘campaign_id’])
params = {‘start_time’:row[‘startdt’],‘end_time’:row[‘enddt’],‘granularity’:‘DAY’,‘metrics’:‘promoted_video_total_views,promoted_tweet_profile_impressions,promoted_tweet_search_impressions,promoted_tweet_timeline_impressions,promoted_tweet_search_engagements,promoted_tweet_profile_engagements,promoted_tweet_timeline_engagements,promoted_account_follows,billed_charge_local_micro,billed_engagements,billed_follows,promoted_tweet_search_url_clicks,promoted_tweet_timeline_url_clicks,promoted_tweet_profile_url_clicks,promoted_tweet_search_clicks,promoted_tweet_timeline_clicks,promoted_tweet_profile_clicks’}
response = Request(client, ‘get’, resource, params=params).perform()



@ami_Debapam: Version 0 of the Ads API has been deprecated. Please change your resource paths to /1/accounts/:account_id and /1/stats/accounts/:account_id. The Ads API Version 1.0 documentation may also be helpful.

If you continue to receive 403s after this change, please provide the request using twurl and provide the account and campaign IDs as well as the start and end times you’re trying to retrieve stats for.


@juanshishido : We tried to use twurl , but our application is driven by python . Is there any equivalent for twurl in python Or is it ok if we share the response headers using python ‘requests’ package .
Thank you


@ami_Debapam: If we can determine the exact HTTP call being made, including the relevant account and campaign IDs, and see the associated response, we should be able to help.

As a side note, we prefer twurl because it handles Twitter OAuth authentication and makes it easier to determine the call being made. For example:

$ twurl -X GET -H "/1/accounts"

We’ll keep a look out for your reply.


@juanshishido :

Following is the command we have used :
twurl -X GET -H “/1/stats/accounts/18ce54b5gzd/campaigns/5sq66?granularity=DAY&start_time=2016-10-02T07:00:00Z&end_time=2016-10-03T07:00:00Z”

Below response we got for the same command :
{“errors”:[{“code”:“ROUTE_NOT_FOUND”,“message”:“The requested resource could not be found”}],“request”:{“params”:{}}}karthikr44@ubuntu:~$

Thanks you


@ami_Debapam: Thanks for providing this information using twurl.

Note that in this case, you’re seeing ROUTE_NOT_FOUND versus the Forbidden message you saw previously.

For the stats endpoint, you must specify the entity type and ID(s) as follows: entity=CAMPAIGN&entity_ids=5sq66. You must also specify metric_groups and placement.

Please let us know if this helps or if you’re still seeing any errors.


@juanshishido : Thanks for the help! We are able to get the response now

Quick Question - We were iterating through campaigns using a code like this:
params ={‘start_time’:row[‘startdt’],‘end_time’:row[‘enddt’],‘granularity’:‘DAY’,‘metric_groups’:‘ENGAGEMENT’}

So we have changed this to the following following the Version1 update:
resource = ‘/1/stats/accounts/{accid}/’.format(accid=row[‘account_id’])
params = {‘start_time’:row[‘startdt’],‘end_time’:row[‘enddt’],‘granularity’:‘DAY’,‘metric_groups’:‘ENGAGEMENT’,

response = Request(client, ‘get’, resource, params=params).perform()

But we are getting the following error:
Not able to pull the metrics for the twitter campaign CAMPAIGN_NAME
Traceback (most recent call last):
File “”, line 13, in fetch_metrics
response = Request(client, ‘get’, resource, params=params).perform()
File “C:\Users\USERNAME\AppData\Local\Continuum\Anaconda2\lib\site-packages\twitter_ads\”, line 75, in perform
raise Error.from_response(response)
NotFound: <NotFound object at 0x7e5eaf8L code=404 details=[{u’message’: u’The requested resource could not be found’, u’code’: u’ROUTE_NOT_FOUND’}]>


i have submitted the app for white listing but i cant figure out the error i am getting. Whether it is because of wrong code or the app is not white listed yet. However i am getting “Forbidden” error. Please help me out. Below is the detail error

An uncaught Exception was encountered

Type: Hborras\TwitterAdsSDK\TwitterAds\Errors\Forbidden


Filename: C:\xampp\htdocs\ads_management\application\third_party\twitter\vendor\hborras\twitter-php-ads-sdk\src\TwitterAds.php


@ami_Debapam: Sounds like you were able to get a successful response using twurl. That’s great!

It’s difficult to tell why you’re seeing this error in Python—for example, we don’t have visibility into what the values in the row dict are.

With the twitter-ads Python SDK, have you tried looking at this example instead of using manual requests:


My application has been approved but i am seeing the same issue i.e, Forbidden .


Hi @abrown365241

I’m the developer of the library you’re using.

Try to catch the exception and output the error that Twitter is giving to you.

The most common issue is you’re providing bad credentials to the lib.

Could you share your code in order to try to dig in what’s the problem?

Also, if you think is necessary you can create an issue here:



@juanshishido : Thanks for the response !!! It was helpful for sorting out the problem .

We have another query .

In the current version of the updated API twitter , we can find that we are not able to do more than 250 ratelimit response . We had to give some time duration after every 250 ratelimits .

Could you please confirm whether only 250 ratelimits are only allowed .



Hi !!

We have another doubt in getting the response for different campaign_ids .

Could you please help us in finding out a way to pull the response for only the campaign_ids for which any data is present .

Because currently we are loosing a number of rate limits in checking for those campaign_ids which doesn’t have any data .



@ami_Debapam: Please see the Analytics Best Practices doc. While it doesn’t address your question specifically, it provides good information about using the analytics endpoint. The best advice we can provide is to restrict your requests to dates and times—start_time and end_time—during which your campaigns are active. When you search outside of these bounds, you’ll see nulls. Hope this helps!