xquik/x-twitter-scraper
Composer 安装命令:
composer require xquik/x-twitter-scraper
包简介
Xquik PHP SDK for tweet search, profile tweets, followers, webhooks, and automation. Not affiliated with X Corp.
关键字:
README 文档
README
Xquik is an independent third-party service. Not affiliated with X Corp. "Twitter" and "X" are trademarks of X Corp.
The Xquik PHP SDK is a Twitter API SDK and X API alternative for tweet search, advanced Twitter search queries, profile tweets, user lookup, follower export, media download, media upload, monitoring, webhooks, and posting automation.
Use it from PHP 8.1.0+ applications to get tweets from profiles, search tweets by keyword or operator query, send tweets, post replies, like, repost, follow, DM, run giveaway draws, and automate X workflows.
It is generated with Stainless.
Documentation
The REST API documentation can be found on xquik.com.
Installation
Install the package from Packagist with Composer:
composer require xquik/x-twitter-scraper:^0.4.4
Usage
This library uses named parameters to specify optional arguments. Parameters with a default value must be set by name.
<?php use XTwitterScraper\Client; $client = new Client( apiKey: getenv('X_TWITTER_SCRAPER_API_KEY') ?: 'My API Key' ); $paginatedTweets = $client->x->tweets->search(q: 'from:elonmusk', limit: 10); var_dump($paginatedTweets->has_next_page);
Value Objects
It is recommended to use the static with constructor Dog::with(name: "Joey")
and named parameters to initialize value objects.
However, builders are also provided (new Dog)->withName("Joey").
Handling errors
When the library is unable to connect to the API, or if the API returns a non-success status code (i.e., 4xx or 5xx response), a subclass of XTwitterScraper\Core\Exceptions\APIException will be thrown:
<?php use XTwitterScraper\Core\Exceptions\APIConnectionException; use XTwitterScraper\Core\Exceptions\RateLimitException; use XTwitterScraper\Core\Exceptions\APIStatusException; try { $account = $client->account->retrieve(); } catch (APIConnectionException $e) { echo "The server could not be reached", PHP_EOL; var_dump($e->getPrevious()); } catch (RateLimitException $e) { echo "A 429 status code was received; we should back off a bit.", PHP_EOL; } catch (APIStatusException $e) { echo "Another non-200-range status code was received", PHP_EOL; echo $e->getMessage(); }
Error codes are as follows:
| Cause | Error Type |
|---|---|
| HTTP 400 | BadRequestException |
| HTTP 401 | AuthenticationException |
| HTTP 403 | PermissionDeniedException |
| HTTP 404 | NotFoundException |
| HTTP 409 | ConflictException |
| HTTP 422 | UnprocessableEntityException |
| HTTP 429 | RateLimitException |
| HTTP >= 500 | InternalServerException |
| Other HTTP error | APIStatusException |
| Timeout | APITimeoutException |
| Network error | APIConnectionException |
Retries
Certain errors will be automatically retried 2 times by default, with a short exponential backoff.
Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict, 429 Rate Limit, >=500 Internal errors, and timeouts will all be retried by default.
You can use the maxRetries option to configure or disable this:
<?php use XTwitterScraper\Client; // Configure the default for all requests: $client = new Client(requestOptions: ['maxRetries' => 0]); // Or, configure per-request: $result = $client->account->retrieve(requestOptions: ['maxRetries' => 5]);
File uploads
Request parameters for file uploads accept a resource from fopen(), raw contents, or a FileParam.
<?php use XTwitterScraper\Core\FileParam; $contents = file_get_contents('/path/to/file'); $response = $client->x->media->upload( file: FileParam::fromString($contents, filename: '/path/to/file', contentType: '…'), ); $response = $client->x->media->upload(file: '…'); $fd = fopen('/path/to/file', 'r'); try { $response = $client->x->media->upload( file: FileParam::fromResource($fd, filename: '/path/to/file', contentType: '…'), ); } finally { fclose($fd); }
Advanced concepts
Making custom or undocumented requests
Undocumented properties
You can send undocumented parameters to any endpoint, and read undocumented response properties, like so:
Note: the extra* parameters of the same name overrides the documented parameters.
<?php $account = $client->account->retrieve( requestOptions: [ 'extraQueryParams' => ['my_query_parameter' => 'value'], 'extraBodyParams' => ['my_body_parameter' => 'value'], 'extraHeaders' => ['my-header' => 'value'], ], );
Undocumented request params
If you want to explicitly send an extra param, you can do so with the extra_query, extra_body, and extra_headers under the request_options: parameter when making a request, as seen in the examples above.
Undocumented endpoints
To make requests to undocumented endpoints while retaining the benefit of auth, retries, and so on, you can make requests using client.request, like so:
<?php $response = $client->request( method: "post", path: '/undocumented/endpoint', query: ['dog' => 'woof'], headers: ['useful-header' => 'interesting-value'], body: ['hello' => 'world'] );
Versioning
This package follows SemVer conventions. As the library is in initial development and has a major version of 0, APIs may change at any time.
This package considers improvements to the (non-runtime) PHPDoc type definitions to be non-breaking changes.
Requirements
PHP 8.1.0 or higher.
Contributing
xquik/x-twitter-scraper 适用场景与选型建议
xquik/x-twitter-scraper 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「sdk」 「automation」 「API-Client」 「webhooks」 「twitter-api」 「x-api」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 xquik/x-twitter-scraper 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 xquik/x-twitter-scraper 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 xquik/x-twitter-scraper 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Skolkovo API Client
Command-line utility for Vtiger CRM.
Historical accounting for contacts
Extends Mautic Lead Bundle's Lead List (Segment) functionality.
A client library for the OpenPLZ API project
A PHP code checks automation tool that can be used as git pre-commit hook.
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 41
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2026-04-01