https://github.com/bitly-community/bitly-php
🔗 PHP library for Bitly API.
https://github.com/bitly-community/bitly-php
bitly bitly-api bitly-php-sdk composer composer-package janephp library package php php-library php-sdk sdk sdk-php
Last synced: 4 months ago
JSON representation
🔗 PHP library for Bitly API.
- Host: GitHub
- URL: https://github.com/bitly-community/bitly-php
- Owner: bitly-community
- License: mit
- Created: 2025-02-26T00:17:23.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-11-24T14:36:49.000Z (7 months ago)
- Last Synced: 2025-11-27T13:58:04.453Z (7 months ago)
- Topics: bitly, bitly-api, bitly-php-sdk, composer, composer-package, janephp, library, package, php, php-library, php-sdk, sdk, sdk-php
- Language: PHP
- Homepage: https://packagist.org/packages/bitly-api/sdk
- Size: 1.02 MB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# bitly-php
[](https://packagist.org/packages/bitly-api/sdk)
[](https://github.com/bitly-community/bitly-php/actions/workflows/build.yml)
[](https://github.com/bitly-community/bitly-php/actions/workflows/test.yml)
PHP library for [Bitly](https://bitly.com/). Code is generated using the [OpenAPI spec](https://dev.bitly.com/docs/sdks/openapi-30/). See the [API reference](https://dev.bitly.com/api-reference).
## Requirements
### Version
PHP >=8.0
### API Key
Generate an [access token](https://app.bitly.com/settings/api/).
## Install
Install the package with [Composer](https://getcomposer.org/):
```sh
composer require bitly-api/sdk
```
If you're missing a package providing `psr/http-client-implementation`:
```sh
composer require php-http/guzzle7-adapter
```
Add [autoloading](https://getcomposer.org/doc/01-basic-usage.md#autoloading):
```php
require_once 'vendor/autoload.php';
```
## Usage
Instantiate the SDK:
```php
use Bitly\Bitly;
$bitly = new Bitly('YOUR_API_KEY');
$client = $bitly->client;
```
Convert a long URL to a Bitlink:
```php
use Bitly\Bitly;
use Bitly\Model\Shorten;
$bitly = new Bitly('YOUR_API_KEY');
$shorten = new Shorten();
$shorten->setLongUrl('https://example.com/my-long-url');
$response = $bitly->client->createBitLink($shorten);
```
Handle an API error:
```php
use Bitly\Bitly;
$bitly = new Bitly('YOUR_API_KEY');
try {
$bitly->client->getBitlink('http://bit.ly/2OUJim0');
} catch (Throwable $exception) {
echo $exception->getMessage();
echo $exception->getCode();
}
```
## Scripts
### `composer build`
Generate the code:
```sh
composer build
```
### `composer clean`
Delete the `lib/` directory:
```sh
composer clean
```
### `composer test`
Run the tests:
```sh
composer test
```
## About This Package
This package is automatically generated by [Jane](https://github.com/janephp/janephp).