商业人士/exavault-php-sdk

该软件包的最新版本(dev-master)没有提供许可信息。

ExaVault PHP SDK

dev-master 2019-05-15 08:21 UTC

This package is not auto-updated.

Last update: 2021-08-13 21:47:54 UTC


README

evapi-php 是一个用 PHP 编写的 API 客户端,用于连接到 ExaVault API。ExaVault API 是一个类似于 REST 的 API,提供文件和用户管理操作,支持 POSTGET 请求。

要开始使用 ExaVault 的 API,您首先必须拥有 ExaVault 账户并获得 API 密钥。有关更多信息,请参阅我们的开发者页面或联系support@exavault.com获取详细信息。

先决条件

PHP 5.4.0 及以上版本

安装

$ composer require commercialpeople/exavault-php-sdk:"dev-master"

入门指南

您需要从您的账户的客户区域获取应用程序的 API 密钥。要获取 API 密钥,请按照以下说明操作。

  • 登录到客户区域的账户部分。
  • 使用您所需账户旁边的下拉菜单,并选择 管理 API 密钥
  • 您将被带到 API 密钥管理屏幕。填写表单并保存以生成您应用程序的新密钥。

一旦您获得 API 密钥,您可以使用以下片段。它将允许您通过 API 进行身份验证、创建文件夹、获取活动日志并从 API 中注销用户。

<?php

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

// Authenticate User
$authApi = new ExaVault\Sdk\Api\AuthenticationApi();
$apiKey = '<api-key>';
$username = '<username>';
$password = '<password>'; 
$accessToken = '<token>';

try {

  $response = $authApi->authenticateUser($apiKey, $username, $password);
  $loginSuccess = $response['success'];

  if ($loginSuccess) {
    $accessToken = $response['results']['access_token'];
  } else {
    // something went wrong check $response['error'] for more details
    throw new Exception($response['error']['message']);
  }

} catch (Exception $e) {
    // server error occurred
    echo 'Exception when calling AuthenticationApi->authenticateUser: ', $e->getMessage(), PHP_EOL;
    exit;
}

// Create Folder
$fsApi = new ExaVault\Sdk\Api\FilesAndFoldersApi();
$folderName = 'api_test_folder'.rand();
$path = '/';

try{

  $response = $fsApi->createFolder($apiKey, $accessToken, $folderName, $path);
  $createSuccess = $response['success'];

  if ($createSuccess) {
    // Folder created successfully
    echo ('Folder created successfully');
  }
  else{
    // something went wrong check $response['error'] for more details
    throw new Exception($response['error']['message']);
  }

} catch (Exception $e) {
    // server error occurred
    echo 'Exception when calling FilesAndFoldersApi->createFolder: ', $e->getMessage(), PHP_EOL;
    exit;
}

// Get Activity Logs
$activityApi = new ExaVault\Sdk\Api\ActivityApi();
$offset = 0;
$sort_by = 'sort_logs_date'; 
$sort_order = 'desc'; 

try {

  $response = $activityApi->getFileActivityLogs($apiKey, $accessToken, $offset, $sort_by, $sort_order);
  $getActivitySuccess = $response['success'];


  if ($getActivitySuccess) {
    // Geat array with log entries
    $activityLogs = $response['results'];
    print_r($activityLogs);
  }
  else{
    // something went wrong check $response['error'] for more details
    throw new Exception($response['error']['message']);
  }

} catch (Exception $e) {
    echo 'Exception when calling ActivityApi->getFileActivityLogs: ', $e->getMessage(), PHP_EOL;
    exit;
}

// To logout the current user, simply check the $loginSuccess flag
// that was stored earlier and then call the `logoutUser` method
if ($loginSuccess) {
  $authApi->logoutUser($apiKey, $accessToken);
}

您可以在以下链接找到所有 API 请求的列表 - ExaVault API 文档