samlitowitz/twitter-php-openapi

Twitter API v2 可用端点

v2.0.0 2022-06-11 15:34 UTC

This package is auto-updated.

Last update: 2024-09-11 20:17:52 UTC


README

Twitter API v2 可用端点

更多信息,请访问 https://developer.twitter.com/.

安装与使用

要求

PHP 7.4 及以上版本。也适用于 PHP 8.0。

Composer

要通过 Composer 安装绑定,请在 composer.json 中添加以下内容

{
  "repositories": [
    {
      "type": "vcs",
      "url": "https://github.com/samlitowitz/twitter-php-openapi.git"
    }
  ],
  "require": {
    "samlitowitz/twitter-php-openapi": "*@dev"
  }
}

然后运行 composer install

手动安装

下载文件并包含 autoload.php

<?php
require_once('/path/to/OpenAPIClient-php/vendor/autoload.php');

入门指南

请按照安装说明进行操作,然后运行以下命令

<?php
require_once(__DIR__ . '/vendor/autoload.php');



// Configure OAuth2 access token for authorization: OAuth2UserToken
$config = OpenAPI\Client\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');


$apiInstance = new OpenAPI\Client\Api\BookmarksApi(
    // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
    // This is optional, `GuzzleHttp\Client` will be used as default.
    new GuzzleHttp\Client(),
    $config
);
$id = 'id_example'; // string | The ID of the authenticated source User for whom to return results.
$max_results = 56; // int | The maximum number of results.
$pagination_token = 'pagination_token_example'; // string | This parameter is used to get the next 'page' of results.
$tweet_fields = ["attachments","author_id","context_annotations","conversation_id","created_at","entities","geo","id","in_reply_to_user_id","lang","non_public_metrics","organic_metrics","possibly_sensitive","promoted_metrics","public_metrics","referenced_tweets","reply_settings","source","text","withheld"]; // string[] | A comma separated list of Tweet fields to display.
$expansions = ["attachments.media_keys","attachments.poll_ids","author_id","entities.mentions.username","geo.place_id","in_reply_to_user_id","referenced_tweets.id","referenced_tweets.id.author_id"]; // string[] | A comma separated list of fields to expand.
$media_fields = ["alt_text","duration_ms","height","media_key","non_public_metrics","organic_metrics","preview_image_url","promoted_metrics","public_metrics","type","url","variants","width"]; // string[] | A comma separated list of Media fields to display.
$poll_fields = ["duration_minutes","end_datetime","id","options","voting_status"]; // string[] | A comma separated list of Poll fields to display.
$user_fields = ["created_at","description","entities","id","location","name","pinned_tweet_id","profile_image_url","protected","public_metrics","url","username","verified","withheld"]; // string[] | A comma separated list of User fields to display.
$place_fields = ["contained_within","country","country_code","full_name","geo","id","name","place_type"]; // string[] | A comma separated list of Place fields to display.

try {
    $result = $apiInstance->getUsersIdBookmarks($id, $max_results, $pagination_token, $tweet_fields, $expansions, $media_fields, $poll_fields, $user_fields, $place_fields);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling BookmarksApi->getUsersIdBookmarks: ', $e->getMessage(), PHP_EOL;
}

API 端点

所有 URI 都相对于 https://api.twitter.com

模型

授权

Bearer令牌

  • 类型:Bearer身份验证

OAuth2用户令牌

  • 类型OAuth
  • 流程accessCode
  • 授权URLhttps://api.twitter.com/2/oauth2/authorize
  • 作用域:
    • block.read:您已屏蔽的账户。
    • block.write:为您屏蔽和解除屏蔽账户。
    • bookmark.read:允许应用程序读取书签推文。
    • bookmark.write:允许应用程序创建和删除书签。
    • follows.read:关注您的人和您关注的人。
    • follows.write:为您关注和取消关注人。
    • like.read:您已点赞的推文和您可以查看的点赞。
    • like.write:为您点赞和取消点赞推文。
    • list.read:您创建或成为成员的列表、列表成员和列表关注者,包括私有列表。
    • list.write:为您创建和管理列表。
    • mute.read:您已静音的账户。
    • mute.write:为您静音和解除静音账户。
    • space.read:访问您可以看到的所有Spaces。
    • tweet.moderate.write:隐藏和取消隐藏您推文的回复。
    • tweet.read:您可以看到的所有推文,包括受保护账户的推文。
    • tweet.write:为您推文和转发推文。
    • users.read:您可以查看的任何账户,包括受保护账户。您可以查看的任何账户,包括受保护账户。

用户令牌

测试

要运行测试,请使用

composer install
vendor/bin/phpunit

作者

关于此包

本PHP软件包由OpenAPI Generator项目自动生成

  • API版本:2.45
  • 构建包:org.openapitools.codegen.languages.PhpClientCodegen