定制 phonghaw2/laravel-x-api-v2 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

phonghaw2/laravel-x-api-v2

最新稳定版本:v1.0.0

Composer 安装命令:

composer require phonghaw2/laravel-x-api-v2

包简介

A small Laravel package for X API.

README 文档

README

MIT Licensed Total Downloads

Installation

For Laravel ^6.0|^7.0|^8.0

This package can be installed through Composer.

composer require phonghaw2/laravel-x-api-v2

Optionally, you can publish the config file of this package with this command:

php artisan vendor:publish --provider="Phonghaw2\X\XServiceProvider"

Config

The following config file will be published in config/x.php

return [
    'api_base_uri' => 'https://api.twitter.com/2/',

    // The unique identifier for the Twitter account.
    // Account ID of the Twitter user
    'app_id' => env('X_APP_ID', 1),

    // Your Twitter API consumer key (public key), obtained from the Twitter Developer Portal.
    // This key is used to identify your app when making API requests. (Consumer API key)
    'api_key' => env('X_APP_KEY', 'CONSUMER_KEY'),

    // Your Twitter API consumer secret, also obtained from the Twitter Developer Portal.
    'api_key_secret' => env('X_APP_KEY_SECRET', 'CONSUMER_SECRET'),

    // The bearer token, used for OAuth 2.0 authentication.
    // It is used in the HTTP headers when making requests to Twitter's API without the need for user authentication.
    'bearer_token' => env('X_BEARER_TOKEN', 'BEARER_TOKEN'),

    // Access token, used for user authentication and authorization for Twitter API access on behalf of the user.
    // You must request this token after getting user consent.
    'access_token' => env('X_ACCESS_TOKEN', 'ACCESS_TOKEN'),

    // Access token secret, paired with the access token to authenticate and authorize API calls.
    'access_token_secret' => env('X_ACCESS_TOKEN_SECRET', 'ACCESS_TOKEN_SECRET'),
];

Usage

Here are a few examples of the provided methods:

TweetLookup

use Twitter;
// Post lookup by Post IDs
Twitter::tweetLookup()
->setQueryParams([
    'ids' => 111111111,
    'max_results' => 5, // Must be a number between 1 and 100 (default: 100)
    'pagination_token' => '5qym3iwo3naekslszn59lxy1d9nmc6q'
])
->lookupPost();

// Creation of a Post
Twitter::tweetLookup()
->setPostData([
    'media' => [
        "media_ids": [
            "11111"
        ],
        "tagged_user_ids": [
            "2222"
        ]
    ],
])
->create()

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-22