PHPackages                             pmg/twitterads - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. pmg/twitterads

ActiveLibrary[API Development](/categories/api)

pmg/twitterads
==============

A Twitter Ads SDK

v1.0.2(9y ago)08.8k1[1 issues](https://github.com/AgencyPMG/TwitterAds-PHP/issues)MITPHP

Since Jul 19Pushed 8y ago6 watchersCompare

[ Source](https://github.com/AgencyPMG/TwitterAds-PHP)[ Packagist](https://packagist.org/packages/pmg/twitterads)[ RSS](/packages/pmg-twitterads/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (5)Versions (4)Used By (0)

[![Coverage Status](https://camo.githubusercontent.com/1f996a390ff893f35c813ec44b37f162f942b5f2b01dd64b68972c9d16b8f1b9/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f4167656e6379504d472f547769747465724164732d5048502f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/AgencyPMG/TwitterAds-PHP?branch=master)[![Build Status](https://camo.githubusercontent.com/d945e7b8c601a27f9c905170d961ad377578ac817846dc2419f56c87eea6f10c/68747470733a2f2f7472617669732d63692e6f72672f4167656e6379504d472f547769747465724164732d5048502e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/AgencyPMG/TwitterAds-PHP)

TwitterAds-PHP
==============

[](#twitterads-php)

A simple Twitter Ads SDK for PHP, powered by Guzzle.

Installing
----------

[](#installing)

```
you@yourcomputer:yourproject> composer require pmg/twitterads
```

Initializing the client
-----------------------

[](#initializing-the-client)

Initializing the client is simple. Just supply your keys and go!

```
$twitter = new \PMG\TwitterAds\TwitterAds(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, TOKEN_SECRET);
//We will assume for the rest of the examples that $twitter is defined.
```

Requests
--------

[](#requests)

For each entity in the Twitter Ads API, there is an available request object. I attempt to keep the endpoints exactly as they appear in the API docs, however there are a few things to keep in mind.

- Route parameters are fulfilled in an array after the requested API endpoint (See example below)
- Each endpoint has a default `HttpMethod` assigned to it, however this can be overridden in the constructor for each `Request` type
- Requests have the following constructor signature: `__construct($url, $params=[], $headers=[], $method=null)` where `$url` is the API endpoint, `$params` is the body/route parameters, `$headers` is an associative array of headers to send with the request, and `$method` is used to override the default `HttpMethod`

An example of making a request:

```
use PMG\TwitterAds\TailoredAudiences\TailoredAudienceRequest;

$request = new TailoredAudienceRequest('accounts/:account_id/tailored_audiences', ['account_id' => ACCOUNT]);
$response = $twitter->send($request);

//Returns PMG\TwitterAds\Response
```

Responses
---------

[](#responses)

All requests, if successful, will return a `PMG\TwitterAds\Response` which is a simple wrapper around the Guzzle response that was received back after making the request. The request also implements `Arrayable` which allows converting the request into an array.

Example array response:

```
object(PMG\TwitterAds\Response)#228 (3) {
  ["code":"PMG\TwitterAds\Response":private]=>
  int(200)
  ["headers":"PMG\TwitterAds\Response":private]=>
  array(8) {
    ["content-length"]=>
    string(4) "3749"
    ["content-type"]=>
    string(30) "application/json;charset=utf-8"
    ["date"]=>
    string(29) "Tue, 19 Jul 2016 14:55:21 GMT"
    ["expires"]=>
    string(29) "Tue, 31 Mar 1981 05:00:00 GMT"
    ["status"]=>
    string(6) "200 OK"
    ["x-rate-limit-limit"]=>
    string(2) "15"
    ["x-rate-limit-remaining"]=>
    string(2) "13"
    ["x-rate-limit-reset"]=>
    string(10) "1468940943"
  }
  ["body":"PMG\TwitterAds\Response":private]=>
  array(2) {
    ["id"]=>
    int(2222)
    ["id_str"]=>
    string(9) "2222"
  }
}
```

Using the TON API
-----------------

[](#using-the-ton-api)

I provide 2 methods of using the TON API.

- `PMG\TwitterAds\Ton\TonRequest`
- `PMG\TwitterAds\Ton\TonUpload`

I strongly recommend using the latter of the 2 options because `TonUpload` was designed to handle any batched uploads that may need to happen and will handle all requests required to fulfil the upload.

`TonRequest` works like any other request in this SDK.

And example of `TonUpload`

```
$file = new \SplFileObject('somefile.txt');
$tonFile = new TonUpload($twitter, $file, 'text/plain');

$response = $tonFile->upload();

//Returns PMG\TwitterAds\Response
```

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

3634d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d396af79150164dd4d28f3e816b377e2f3c04df431d8338477517efa0013664c?d=identicon)[chrisguitarguy](/maintainers/chrisguitarguy)

---

Top Contributors

[![Blackburn29](https://avatars.githubusercontent.com/u/1065472?v=4)](https://github.com/Blackburn29 "Blackburn29 (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/pmg-twitterads/health.svg)

```
[![Health](https://phpackages.com/badges/pmg-twitterads/health.svg)](https://phpackages.com/packages/pmg-twitterads)
```

###  Alternatives

[statamic/cms

The Statamic CMS Core Package

4.8k3.6M966](/packages/statamic-cms)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3741.3M46](/packages/tencentcloud-tencentcloud-sdk-php)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k656.1k38](/packages/neuron-core-neuron-ai)[avalara/avataxclient

Client library for Avalara's AvaTax suite of business tax calculation and processing services. Uses the REST v2 API.

528.5M7](/packages/avalara-avataxclient)[files.com/files-php-sdk

Files.com PHP SDK

2481.1k](/packages/filescom-files-php-sdk)[aimeos/prisma

A powerful PHP package for integrating media related Large Language Models (LLMs) into your applications

1943.1k5](/packages/aimeos-prisma)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
