Twitter Ads API - PHP SDK - Version 2



We are using PHP SDK for Twitter ADS API. It seems that Twitter has introduced Version 2.0 for Ads API. But under twitter Libraries PHP, the SDK available only for Version 1.0.

Please share the PHP SDK kit for Version 2.



The PHP SDK was updated to v2 and seems to have some commits even newer than that, please take a look at and feel free to leave feedback/issues there if you have any issues.



Thank you for sharing the details. The challenge here is that in Version 1 we were referring Abraham library. In the version 2 SDK, the objects/functions are different, so now we have to write our code again from scratch.


I see - I don’t see many details specific to Ads API in the Abraham one you link to, did you fork that one and add Ads API functionality on top of it? A lot of the change is just changing the 1 in the path to a 2. In worst case you could look through the commits that were done to the other SDKs to see what needs to be updated. Also if there’s a reason you can or cannot adopt one of the SDKs that has been updated it’s good feedback.



Hello John,

I have updated my code and tried 2 different approaches.

  1. Update 1 to 2 in current SDK Path.
  2. Download and use new SDK (Version 2)

In both the cases, I am getting error “Unauthorized Access”. The credentials and tokens are same. We were pulling the data from last 2 years with the same details.

Please let me know if there are any changes happen for authorization.

Deepak Garg


That error would happen if your App ID is not the one you expect as well - so please check you are using the consumer key of the app that was whitelisted for Ads API. You should be able to walk through and test hitting twurl first just to figure out your authentication issues. “twurl -T” gives a tutorial for how to set up authentication for your consumer key.


Hello Joan,

Thank you for the support. We had resolved the issue. It is not related to APP ID or Consumer Key.

Below is the change which we had done and we are able to pull data from both SDK.

In Version 2 SDK

File: Request.php
Replace public static $version = ‘2.0’; with public static $version = ‘1.0’;

In Version 1 SDK

File: TwitterOAuth.php
Replace const API_VERSION = ‘1’; with const API_VERSION = ‘2’;

Deepak Garg