onlime/bexio-api-client

Bexio API 客户端库

0.5.0 2023-09-27 11:56 UTC

This package is auto-updated.

Last update: 2024-08-27 14:15:22 UTC


README

bexio API 客户端库允许您与 bexio API 进行交互。这是一个早期版本,仍在开发中。

有关如何使用 API 的更多信息,请参阅 bexio API 文档

安装

您可以使用 Composer 或下载库。

使用 Composer 需要此包

$ composer require onlime/bexio-api-client

包含自动加载器

require_once '/path/to/your-project/vendor/autoload.php';

示例

一个完整的工作示例可以在 samples/ 目录中找到。

进行认证以获取访问和刷新令牌

<?php
require_once '../vendor/autoload.php';

use Bexio\Client;

/**
 * $clientId: The client ID you have received from Bexio developer portal (https://developer.bexio.com/).
 * $clientSecret: The client secret you have received from Bexio developer portal (https://developer.bexio.com/).
 * $redirectUrl: Set your URL where this script gets called and set it as allowed redirect URL in your app settings in Bexio developer portal (https://developer.bexio.com/).
 * $scopes: A list of scopes (see https://docs.bexio.com/#section/Authentication/API-Scopes).
 * $tokensFile: Set the path where the credentials file will be stored.
 */
$clientId = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';
$clientSecret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$redirectUrl = 'https://:8000/auth.php';
$scopes = ['openid', 'profile', 'contact_edit', 'offline_access', 'kb_invoice_edit', 'bank_payment_edit'];
$tokensFile = 'client_tokens.json';

$client = new Client($clientId, $clientSecret);
$client->authenticate($scopes, $redirectUrl);
$client->persistTokens($tokensFile);

初始化客户端

<?php
require_once '../vendor/autoload.php';

use Bexio\Client;

$clientId = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';
$clientSecret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$tokensFile = 'client_tokens.json';

$client = new Client($clientId, $clientSecret);
$client->loadTokens($tokensFile);

获取联系人

<?php
use Bexio\Resource\Contact;

$bexioContact = new Contact($client);
$contacts = $bexioContact->getContacts();

用法

  1. 确保您已在 Bexio 开发者门户 中允许您的本地直接 URL,例如 https://:8000/auth.php
  2. samples/auth.phpsamples/sample.php 中填写 $clientId$clientSecret,以您的 Bexio API 凭证。
  3. 启动本地开发服务器(见下文)。
  4. 在浏览器中访问 https://:8000/auth.php
  5. 使用您的 Bexio 登录进行认证,通过访问令牌提供对应用程序的访问。
  6. Bexio 将您重定向回 https://:8000/auth.php,将显示: 认证成功。 转到 sample.php
  7. 一旦您访问 https://:8000/sample.php,您应该已经认证(使用存储在 client_tokens.json 中的当前令牌)并且您的联系人已列出。
$ cd samples/
$ php -S localhost:8000

作者

此出色软件包的作者是 Philip Iezzi (Onlime GmbH)

此包的大部分内容是从原始的 christianruhstaller/bexio-api-php-client 移植的。感谢 Christian Ruhstaller,那位气球先生。

此分支于 2022 年 3 月从原始存储库中分离出来,因为代码库已经相当大的分歧。请注意:两个项目目前都不代表一个完整的 Bexio API 客户端库,两者都仅限于所有 API 方法的一个子集。

许可证

此软件包根据 MIT 许可证 授权,但支持是欢迎的。