承接 phplicengine/bitly 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

phplicengine/bitly

最新稳定版本:v1.0.5

Composer 安装命令:

composer require phplicengine/bitly

包简介

Bitly API v4

README 文档

README

Build Status Scrutinizer Code Quality Latest Stable Version Total Downloads Release date php License

Bitly API v4

Contents

Installation

composer require phplicengine/bitly

Usage

use PHPLicengine\Api\Api;
use PHPLicengine\Service\Bitlink;

$api = new Api("API KEY GOES HERE");
$bitlink = new Bitlink($api);
$result = $bitlink->createBitlink(['long_url' => 'http://www.example.com']);

// if cURL error occurs.
if ($api->isCurlError()) {
    
    print($api->getCurlErrno().': '.$api->getCurlError());
    
} else {

    // if Bitly response contains error message.
    if ($result->isError()) {

        print("Error:<br />");
        print($result->getResponse());
        print($result->getDescription());
    
    } else {
    
        // if Bitly response is 200 or 201
        if ($result->isSuccess()) {
        
            print("SUCCESS:<br />");
            print($result->getResponse());
            print_r($result->getResponseArray());

        } else {

            print("FAIL:<br />");
            print($result->getResponse());
            print_r($result->getResponseArray());

        }
    }
}

// for debug only.
print("INFO:<br />");

// returns response exactly as it is. e.g. json.
$resj = $result->getResponse();
print($resj."<br />");

// returns decoded json.
$reso = $result->getResponseObject();
print_r($reso);

// returns header of server.
$resh = $result->getHeaders();
print_r($resh);

// returns request.
$resr = $api->getRequest();
print_r($resr);

Manual

Service Classes

In Bitly API v4 documentations, resources are classified under serveral categories:

Bitlink, Group, Organization, User, Custom, Campaign, Bsd, OAuth, Auth, Webhook

We made each of them as a separate service class. Method names are the same as the last part of documentation url. For example if you want to use Get Metrics for a Bitlink by Country, this one is classified under Bitlink category in documentation and the last part of its url is getMetricsForBitlinkByCountries, so you can call it this way:

use PHPLicengine\Api\Api;
use PHPLicengine\Service\Bitlink;

$api = new Api("API KEY GOES HERE");
$bitlink = new Bitlink($api);
$result = $bitlink->getMetricsForBitlinkByCountries('bit.ly/34nRNvl', ['unit' => 'day', 'units' => -1]);

All Path parameters, must be passed as string in first argument of methods if necessary and all Query parameters must be passed as array in second argument of methods if necessary. If Path parameter is not needed, Query parameters will be first argument of methods.

Another example:

Retrieve Group Shorten Counts is classified under Group category, and the last part of its link is getGroupShortenCounts, so you can call it this way:

use PHPLicengine\Api\Api;
use PHPLicengine\Service\Group;

$api = new Api("API KEY GOES HERE");
$group = new Group($api);
$result = $group->getGroupShortenCounts($group_guid);

Here is list of available service classes and methods.

Custom cURL Options

By default cURL timeout is 30. You can change it with:

$api->setTimeout(30);

If you need to add some CURLOPT_* constants that are not enabled by default, you can call setCurlCallback() method to add them.

use PHPLicengine\Api\Api;
use PHPLicengine\Service\Bitlink;

$api = new Api("API KEY GOES HERE");
$api->setCurlCallback(function($ch, $params, $headers, $method) { 
      curl_setopt($ch, CURLOPT_*, 'some value'); 
}); 
$bitlink = new Bitlink($api);

This is added for your convenience, but you should not need it.

Contributing and Support

For all issues or feature request or support questions please open a new issue. All pull requests are welcome.

License

PHPLicengine Api is distributed under the Apache License. See License.

统计信息

  • 总下载量: 266.51k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 22
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 1

GitHub 信息

  • Stars: 21
  • Watchers: 2
  • Forks: 81
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2019-10-30