narendravaghela/bitly-client

PHP客户端库,用于访问Bitly API

v1.0.0 2016-12-15 12:56 UTC

This package is auto-updated.

Last update: 2024-09-27 03:08:08 UTC


README

Build Status License Latest Stable Version Total Downloads

PHP客户端库,用于访问Bitly API。在Bitly.com注册您的账户,并从此处获取您的访问令牌。

要求

此库有以下要求

  • PHP 5.6.x或更高版本。

安装

您可以使用composer将此库安装到您的应用程序中。

composer require narendravaghela/bitly-client

用法

安装此库后,使用composer自动加载选项加载它,并使用BitlyClient类对象。以下是一个示例:

<?php

require 'vendor/autoload.php';

use Bitly\BitlyClient;

$bitlyClient = new BitlyClient('your-access-token');

$options = ['longUrl' => 'http://www.example.com/a-log-url-slug/'];

$response = $bitlyClient->shorten($options);

响应格式

Bitly支持jsonxmltxt响应类型。您可以在$options数组中指定响应类型。默认响应格式为json

<?php

require 'vendor/autoload.php';

use Bitly\BitlyClient;

$bitlyClient = new BitlyClient('your-access-token');

$options = [
    'longUrl' => 'http://www.example.com/a-log-url-slug/',
    'format' => 'xml' // pass json, xml or txt
];

$response = $bitlyClient->shorten($options);

我们建议仅使用jsonxml格式,因为txt响应有时可能不起作用。

文档

目前,此库为以下模块提供API方法。

报告问题和贡献

如果您对此库有任何问题或任何错误,请在GitHub上打开一个问题。如果您对任何现有错误有解决方案,请创建一个Pull Request。此库遵循PSR-2标准,所以在进行更改时请确保遵循同一标准。