sheettojson-api/client 问题修复 & 功能扩展

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

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

sheettojson-api/client

Composer 安装命令:

composer require sheettojson-api/client

包简介

Official PHP SDK for the SheetToJSON RapidAPI. Turn Google Sheets into a secure CRUD backend.

README 文档

README

Official PHP SDK for the SheetToJSON RapidAPI. Turn any Google Spreadsheet into a secure, blazing-fast REST API with built-in S3 caching and smart querying.

Zero external dependencies. This package uses native PHP cURL for maximum performance and compatibility.

Requirements

  • PHP >= 7.4
  • cURL extension enabled
  • JSON extension enabled

Installation

Install the package via Composer:

composer require sheettojson-api/client

Initialization

Require the Composer autoloader and initialize the SDK with your RapidAPI key.

<?php

require_once 'vendor/autoload.php';

use SheetToJSON\API\SheetToJSON;

// Initialize with your RapidAPI Key
$db = new SheetToJSON('YOUR_RAPIDAPI_KEY');

$SPREADSHEET_ID = '1BxiMVs0XRA5nFMdkvBdBZjgmZ_xyz123'; // Found in your Google Sheet URL
$SHEET_NAME = 'Products'; // The exact name of the tab

Usage Examples

All methods throw an Exception if the API request fails. It is highly recommended to wrap your calls in a try...catch block.

1. Register your Spreadsheet

You must link a spreadsheet to your RapidAPI account once before using the CRUD operations. Don't forget to share your sheet with the service account email first!

try {
    $response = $db->register($SPREADSHEET_ID);
    echo $response['message'];
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}

2. Read and Filter Data (GET)

Retrieve rows with built-in pagination, sorting, and advanced filtering.

try {
    $response = $db->get($SPREADSHEET_ID, $SHEET_NAME, [
        'limit' => 10,           // Max 1000, default 100
        'page' => 1,             
        'price' => 'gt:50',      // Advanced filter: Price Greater Than 50
        'category' => 'lk:tech', // Advanced filter: Category Contains (Like) "tech"
        'sort' => 'price:desc'   // Sort by price descending
    ]);

    echo "Found " . $response['meta']['returned_rows'] . " rows.\n";
    print_r($response['data']);
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}

3. Insert Data (POST)

Add new rows to the bottom of your sheet. You can pass a single associative array or an array of arrays for batch insertion.

try {
    $newProducts = [
        [
            'id' => 105, 
            'name' => 'Wireless Mouse', 
            'price' => 25.99, 
            'stock' => 150
        ],
        [
            'id' => 106, 
            'name' => 'Mechanical Keyboard', 
            'price' => 89.00, 
            'stock' => 40
        ]
    ];

    $response = $db->insert($SPREADSHEET_ID, $SHEET_NAME, $newProducts);
    echo $response['message']; // "2 row(s) successfully inserted."
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}

4. Update Data (PATCH)

Update specific fields of an existing row. Provide the column name (lookup_key) and the value (lookup_value) to find the exact row to update.

try {
    // Find the row where 'id' equals 105, and update its price and stock
    $response = $db->update($SPREADSHEET_ID, $SHEET_NAME, 'id', 105, [
        'price' => 19.99,
        'stock' => 140
    ]);

    print_r($response['updated_data']);
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}

5. Delete Data (DELETE)

Delete a row from your sheet using the lookup system.

try {
    // Find and delete the row where 'id' equals 105
    $response = $db->delete($SPREADSHEET_ID, $SHEET_NAME, 'id', 105);
    echo $response['message'];
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固