adenion/blog2social-api-php-sdk 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

adenion/blog2social-api-php-sdk

Composer 安装命令:

composer require adenion/blog2social-api-php-sdk

包简介

Official PHP SDK for the Blog2Social API.

README 文档

README

License: MIT PHP Composer

Official PHP SDK for the Blog2Social API v1.0.

The SDK provides a modern, object-oriented interface for:

  • Authentication
  • Social account management
  • Content publishing
  • Image and video publishing
  • Application management

Designed for modern PHP applications and distributed via Composer.

Features

  • Authenticate Blog2Social API users
  • Connect and manage social media accounts
  • Publish link, image, and video posts
  • Manage applications and API integrations
  • PSR-4 compliant
  • Composer-ready installation
  • PHP 8.1+ support

Installation

Install the SDK via Composer:

composer require adenion/blog2social-api-php-sdk

Requirements

  • PHP 8.1 or higher
  • Composer
  • PHP cURL extension
  • PHP JSON extension

Namespace

Adenion\Blog2Social\Sdk\

The Composer PSR-4 configuration maps this namespace to src/.

Repository

GitHub repository:

https://github.com/adenion/blog2social-api-php-sdk

Quick Start

<?php

declare(strict_types=1);

require __DIR__ . '/vendor/autoload.php';

use Adenion\Blog2Social\Sdk\Client\Blog2SocialClient;

$service_token = 'YOUR_SERVICE_TOKEN';

$client = new Blog2SocialClient(
    $service_token
);

Authentication

Most API requests require both a service_token and an access_token.

Authenticate the user:

$auth_response = $client
    ->authentication()
    ->authenticateUser();

$access_token = $auth_response['access_token'];

Store the returned access token securely and use it for future requests:

$client = new Blog2SocialClient(
    $service_token,
    $access_token
);

List Available Networks

Retrieve all supported social networks:

$networks = $client
    ->network()
    ->listNetwork();

print_r($networks);

Connect a Social Media Account

Generate an authorization URL to connect a social media account.

Example: Connect a Facebook Page.

$response = $client
    ->connection()
    ->addNetwork(
        1,
        1,
        'en'
    );

header(
    'Location: ' . urldecode(
        $response['auth_link']
    )
);

exit;

Network Type Values

0 = Profile
1 = Page
2 = Group

List Connected Accounts

$connections = $client
    ->user()
    ->listUserAuthentications();

print_r($connections);

The returned client_user_network_id is required for publishing posts.

Publish a Link Post

$client_user_network_id = (int) 'YOUR_CLIENT_USER_NETWORK_ID';

$response = $client
    ->share()
    ->createPost(
        $client_user_network_id,
        [
            [
                'client_user_network_id' => $client_user_network_id,
                'title' => 'My first API post',
                'message' => 'Hello from the Blog2Social PHP SDK.',
                'postFormat' => 0,
                'customUrl' => 'https://example.com',
            ],
        ]
    );

print_r($response);

Post Format Values

0 = Link
1 = Image
2 = Video

Publish an Image Post

$response = $client
    ->share()
    ->createPost(
        $client_user_network_id,
        [
            [
                'client_user_network_id' => $client_user_network_id,
                'title' => 'Image Post',
                'message' => 'This is an image post.',
                'postFormat' => 1,
                'mediaObjects' => [
                    [
                        'type' => 'IMAGE',
                        'url' => 'https://example.com/image.jpg',
                    ],
                ],
            ],
        ]
    );

Publish a Video Post

$response = $client
    ->share()
    ->createPost(
        $client_user_network_id,
        [
            [
                'client_user_network_id' => $client_user_network_id,
                'title' => 'Video Post',
                'message' => 'This is a video post.',
                'postFormat' => 2,
                'mediaObjects' => [
                    [
                        'type' => 'VIDEO',
                        'url' => 'https://example.com/video.mp4',
                    ],
                ],
            ],
        ]
    );

Error Handling

The Blog2Social API returns one result object per publication target.

Always evaluate every response item individually.

foreach ($response as $result) {

    if ((int) $result['error'] === 0) {
        echo 'Published successfully.';
        continue;
    }

    echo $result['b2s_error_code'] ?? 'UNKNOWN_ERROR';
}

Exception Handling

try {

    $response = $client
        ->share()
        ->createPost(
            $client_user_network_id,
            $posts
        );

    print_r($response);

} catch (Throwable $exception) {

    echo '<pre>';
    print_r($exception);
    echo '</pre>';
}

Common API Error Codes

TOKEN
CONTENT
RIGHT
LOGIN
LIMIT
RATE_LIMIT
NO_DATA

Available Services

$client->authentication();
$client->network();
$client->connection();
$client->categories();
$client->user();
$client->post();
$client->share();
$client->insights();
$client->postInsights();
$client->video();
$client->videoUpload();
$client->videoStatus();
$client->app();
$client->userApps();

Development

Install development dependencies:

composer install

Run the test suite:

composer test

phpunit/phpunit is only required for development and automated tests. It is listed under require-dev and is not installed for production consumers when Composer is run with --no-dev.

Contributing

Contributions are welcome.

If you would like to contribute:

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Open a pull request

For larger changes, please open an issue first to discuss the proposed implementation.

Security

If you discover a security vulnerability, please report it privately and do not create a public GitHub issue.

Please contact:

customer-service@blog2social.com

Support

For support, bug reports, and feature requests:

  • GitHub Issues
  • Blog2Social Support Team

License

This SDK is released under the MIT License.

See the LICENSE file for details.

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-30