officeintegrator/zoi-php-sdk

适用于Zoho Office Integrator的PHP SDK

v1.0.2 2024-08-22 17:58 UTC

This package is auto-updated.

Last update: 2024-09-22 18:22:24 UTC


README

PHP SDK

PHP Version Require Downloads License

目录

入门

Zoho Office Integrator PHP SDK用于帮助您快速集成Zoho Office Integrator编辑器到您的Web应用程序中。

注册Zoho Office Integrator APIKey

由于Zoho Office Integrator API通过apikey进行认证,您应该注册Zoho以获取apikey。要注册您的应用

  • 访问此页面 https://officeintegrator.zoho.com/。 (如果您没有,请注册Zoho账户)

  • 输入您的公司名称并简要描述您将如何在应用程序中使用Zoho Office Integrator。选择应用程序类型(商业或非商业)并生成apikey。

  • 填写以上详细信息后,在Zoho Office Integrator服务中创建一个账户,并从仪表板复制apikey。

环境设置

PHP SDK可以通过composer进行安装。 composer是PHP中的依赖管理工具。Composer从packagist安装PHP SDK到您的应用程序中。

  • 客户端应用程序必须具有PHP(版本7.0及以上)

  • 您的计算机上必须已安装composer

将SDK包含到您的项目中

您可以使用以下方式将SDK包含到项目中

  • getcomposer.org安装composer(如果尚未安装)。

  • 安装PHP SDK

    • 导航到客户端应用程序的工作区。
    • 在应用程序中创建一个composer.json文件,将zoi-nodejs-sdk添加到依赖列表中。 示例
    • 现在运行以下命令
    composer install
  • PHP SDK将被安装,并在您的项目工作区下的vendor文件夹中创建一个名为/zoi-php-sdk-1..的包。

配置

在开始创建PHP应用程序之前,您需要注册Zoho Office Integrator以获取用于认证的apikey。

  • 配置API环境,它决定了API调用的域名和URL。

    /*
     * Refer this help page for api end point domain details -  https://www.zoho.com/officeintegrator/api/v1/getting-started.html
    */
    $environment = new Production("https://api.office-integrator.com");
  • 使用以下脚本配置您从Zoho Office Integrator仪表板获得的apikey。

    /**
     * You can configure where the apikey needs to added in the request object.
     * User can either pass the apikey in the addParam or addHeader method
     */
    $authBuilder = new AuthBuilder();
    $authentication = new Authentication();
    $authBuilder->addParam("apikey", "2ae438cf864488657cc9754a27daa480");
    $authBuilder->authenticationSchema($authentication->getTokenFlow());
    $tokens = [ $authBuilder->build() ];
    $apikey = new APIKey("2ae438cf864488657cc9754a27daa480", Constants::PARAMS);
  • 创建一个Logger类的实例以记录异常和API信息。默认情况下,SDK使用-INFO级别和(sdk_logs.log)(与node_modules平行)的file_path构造一个Logger实例。

    /*
    * Create an instance of Logger Class that requires the following
    * level -> Level of the log messages to be logged. Can be configured by typing Levels "." and choose any level from the list displayed.
    * filePath -> Absolute file path, where messages need to be logged.
    */
    $logger = (new LogBuilder())
            ->level(Levels::INFO)
            ->filePath("./app.log")
            ->build();

初始化应用程序

使用以下代码初始化SDK。

<?php

use com\zoho\api\authenticator\AuthBuilder;
use com\zoho\officeintegrator\dc\apiserver\Production;
use com\zoho\officeintegrator\InitializeBuilder;
use com\zoho\officeintegrator\logger\Levels;
use com\zoho\officeintegrator\logger\LogBuilder;
use com\zoho\officeintegrator\v1\Authentication;

require_once 'vendor/autoload.php';

class Initialize {
    public static function initializeSdk() {

        # Update the api domain based on in which data center user register your apikey
        # To know more - https://www.zoho.com/officeintegrator/api/v1/getting-started.html
        $environment = new Production("https://api.office-integrator.com");
        # User your apikey that you have in office integrator dashboard
        //Update this apikey with your own apikey signed up in office inetgrator service
        $authBuilder = new AuthBuilder();
        $authentication = new Authentication();
        $authBuilder->addParam("apikey", "2ae438cf864488657cc9754a27daa480");
        $authBuilder->authenticationSchema($authentication->getTokenFlow());
        $tokens = [ $authBuilder->build() ];

        # Configure a proper file path to write the sdk logs
        $logger = (new LogBuilder())
            ->level(Levels::INFO)
            ->filePath("./app.log")
            ->build();
        
        (new InitializeBuilder())
            ->environment($environment)
            ->tokens($tokens)
            ->logger($logger)
            ->initialize();

        echo "SDK initialized successfully.\n";
    }
}

Initialize::initializeSdk();
  • 您现在可以通过SDK访问功能。请参阅示例代码,了解如何通过SDK进行各种API调用。

SDK示例代码

  • 确保在运行以下示例代码片段之前已初始化SDK。
  • 参阅此存储库,了解所有Office Integrator API端点的示例代码。

许可

此SDK根据Apache License, Version 2.0分发,有关更多信息,请参阅LICENSE.txt。