nir-arad/php-twitter-client

A Twitter API Client in PHP

dev-master / 1.0.x-dev 2021-01-07 19:10 UTC

This package is auto-updated.

Last update: 2024-06-08 03:05:47 UTC


README

Software License GitHub Release Downloads Latest Version on Packagist Packagist stars

GitHub Code Size GitHub Workflow Build Status GitHub open issues GitHub closed issues

Structure

If any of the following are applicable to your project, then the directory structure should follow industry best practices by being named the following.

bin/        
build/
docs/
config/
src/
tests/
vendor/

Install

Via Composer

$ composer require nir-arad/php-twitter-client

Test

$ composer test

Usage

Below is a usage example to fetch a tweet and display its contents and attributes.

Step 1. Sign up as a developer

Twitter Developer Home

Step 2. Create a project

Step 3. Get project credentials

You will need to obtain both {api_key, api_secret} tokens for Oauth v1 based APIs, and a bearer token for Oauth v2 based APIs.

Store the credentials in a file (e.g. "project.json"). The file format is as follows:

{
    "bearer_token": "AAAAAAAAAAAAAAAAAAAA...",
    "api_key": "4FlE...",
    "api_secret": "OewZ..."
}

Step 4. Obtain user credentials

Store the credentials in a file (e.g. "user.json"). The file format is as follows:

{
    "oauth_token": "123...",
    "oauth_token_secret": "wWby...",
    "user_id": "987...",
    "screen_name": "MyTwitterUser"
}

Step 5. Code example

use NirArad\TwitterClient;

$p_cred = new TwitterClient\ProjectCredentials();
$p_cred->from_file($p_cred_file);

$u_cred = new TwitterClient\UserCredentials();
$u_cred->from_file($u_cred_file);

$client = new TwitterClient\TwitterClient();
$client->project_credentials = $p_cred;
$client->user_credentials = $u_cred;

$params = new TwitterClient\v1\Tweets\GetStatusesLookupQueryParams();
$params_array = array(
    "id" => array(1326023218772144134)
);
$params->from_array($params_array)
$response = $client->GetStatusesLookup($params);

var_dump($response);

Change log

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details.

Security

If you discover any security related issues, please email narad1972@gmail.com instead of using the issue tracker.

Credits

  • [Nir Arad][link-author]
  • [All Contributors][link-contributors]

License

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