kny00 / techspecs-php
PHP 的 TechSpecs API 实现。
v1.0.3
2022-04-14 16:39 UTC
Requires
- php: ^7.4
- guzzlehttp/guzzle: ^7.4
Requires (Dev)
- phpunit/phpunit: 9.5
README
介绍 TechSpecs PHP
这个 PHP 库提供了对全球消费电子产品标准化技术规范自动访问,包括最新的智能手机、平板电脑、智能手表、笔记本电脑等。
文档
API 密钥
- 获取 TechSpecs API 密钥
要求
- PHP 7.4+
- Composer
安装
composer require kny00/techspecs-php-sdk
使用
该库需要使用您的账户 API 密钥和基础 URL 配置,这些信息可在您的 TechSpecs 控制台 中找到。
将 $techSpecsKey
设置为您密钥的值,将 $techSpecsBase
设置为您的基础 URL 值。
基本搜索
通过指定设备型号、版本号或特性来搜索设备
require 'vendor/autoload.php'; // Importing the SDK class use TechSpecsSDK\TechSpecsSDK; // TechSpecs API Key $techSpecsKey = 'techspecs_api_key'; // TechSpecs base https://apis.dashboard.techspecs.io/{techspecs_base} $techSpecsBase = 'a8TD3mkN49fhg2y'; // Instantiate the Library $techSpecs = new TechSpecsSDK($techSpecsBase, $techSpecsKey); // product name or version number to search $keyword = 'iPhone 13'; // product category to search $category = ['all']; // choose between "pretty" or "raw" mode for viewing response $response = $techSpecs->search($keyword, $category, 'pretty'); // print the search results print($response);
高级搜索
按品牌、类别和发布日期列出所有产品
require 'vendor/autoload.php'; // Importing the SDK class use TechSpecsSDK\TechSpecsSDK; // TechSpecs API Key $techSpecsKey = 'techspecs_api_key'; // TechSpecs base https://apis.dashboard.techspecs.io/{techspecs_base} $techSpecsBase = 'a8TD3mkN49fhg2y'; // Instantiate the Library $techSpecs = new TechSpecsSDK($techSpecsBase, $techSpecsKey); // enter the page number to fetch results from $page = 1; /** * Type in the name of the brand you're looking for * or leave this field empty to see results from all brands */ $brand = ['Apple']; /** * Type in the name of the category you're looking for * or leave this field empty to see results from all categories */ $category = ['smartphone']; /** * Please provide a date range to narrow your search. * Leave this field empty to fetch all results from all dates */ $dateFrom = '2010-01-01'; // YYYY-MM-DD $dateTo = '2022-03-15'; // YYYY-MM-DD // Choose between "pretty" or "raw" mode for viewing response $response = $techSpecs->products( $brand, $category, $dateFrom, $dateTo, $page, 'pretty' ); // Print the search results print($response);
产品详情
require 'vendor/autoload.php'; // Importing the SDK class use TechSpecsSDK\TechSpecsSDK; // TechSpecs API Key $techSpecsKey = 'techspecs_api_key'; // TechSpecs base https://apis.dashboard.techspecs.io/{techspecs_base} $techSpecsBase = 'a8TD3mkN49fhg2y'; // Instantiate the Library $techSpecs = new TechSpecsSDK($techSpecsBase, $techSpecsKey); // TechSpecs product id $techspecsId = '6186b047987cda5f88311983'; // choose between "pretty" or "raw" mode for viewing response $response = $techSpecs->productDetail($techspecsId, 'pretty'); // print the specifications of the product print($response);
列出所有品牌
require 'vendor/autoload.php'; // Importing the SDK class use TechSpecsSDK\TechSpecsSDK; // TechSpecs API Key $techSpecsKey = 'techspecs_api_key'; // TechSpecs base https://apis.dashboard.techspecs.io/{techspecs_base} $techSpecsBase = 'a8TD3mkN49fhg2y'; // Instantiate the Library $techSpecs = new TechSpecsSDK($techSpecsBase, $techSpecsKey); // choose between "pretty" or "raw" mode for viewing response $response = $techSpecs->brands('pretty'); // print the search results print($response);
列出所有类别
require 'vendor/autoload.php'; // Importing the SDK class use TechSpecsSDK\TechSpecsSDK; // TechSpecs API Key $techSpecsKey = 'techspecs_api_key'; // TechSpecs base https://apis.dashboard.techspecs.io/{techspecs_base} $techSpecsBase = 'a8TD3mkN49fhg2y'; // Instantiate the Library $techSpecs = new TechSpecsSDK($techSpecsBase, $techSpecsKey); // choose between "pretty" or "raw" mode for viewing response $response = $techSpecs->categories('pretty'); // print the list of all categories print($response);