Coder Social home page Coder Social logo

open-source-contributions / twitter-api-v2-php Goto Github PK

View Code? Open in Web Editor NEW

This project forked from noweh/twitter-api-v2-php

0.0 0.0 0.0 61 KB

PHP package providing easy and fast access to Twitter API V2.

License: MIT License

PHP 98.94% Shell 1.06%

twitter-api-v2-php's Introduction

Twitter API V2 for PHP

php Badge Twitter Run Tests MIT Licensed

Twitter API V2 is a PHP package which provides an easy and fast access to Twitter REST API for Version 2 endpoints.

Installation

First, you need to add the component to your composer.json

composer require noweh/twitter-api-v2-php

Update your packages with composer update or install with composer install.

Github Actions

This repository uses Github Actions for each push/pull request with PHPStan/PHPUnit.

Therefore, for each valid push, a new Tweet is posted from my Twitter test account.

How to use

Active your developer account

Firstly, you need to follow this tutorial.

  • Request of an approved account;
  • Once you have an approved developer account, you will need to create a Project;
  • Enable read/write access for your Twitter app;
  • Generate Consumer Keys and Authentication Tokens;
  • Grab your Keys and Tokens from the twitter developer site.

Prepare settings

Settings are expected as below:

use Noweh\TwitterApi\Client;

$settings = [
    'account_id' => 1234567,
    'consumer_key' => 'CONSUMER_KEY',
    'consumer_secret' => 'CONSUMER_SECRET',
    'bearer_token' => 'BEARER_TOKEN',
    'access_token' => 'ACCESS_TOKEN',
    'acess_token_secret' => 'ACCESS_TOKEN_SECRET'
];

$client = new Client($settings);

To search specific tweets

Example:

$return = $client->tweetSearch()
    ->showMetrics()
    ->onlyWithMedias()
    ->addFilterOnUsernamesFrom([
        'twitterdev',
        'Noweh95'
    ], \Noweh\TwitterApi\Enum\Operators::or)
    ->addFilterOnKeywordOrPhrase([
        'Dune',
        'DenisVilleneuve'
    ], \Noweh\TwitterApi\Enum\Operators::and)
    ->addFilterOnLocales(['fr', 'en'])
    ->showUserDetails()
    ->performRequest()
;

To find Twitter Users

findByIdOrUsername() expects either an array, or a string.

You can specify the search mode as a second parameter:

->findByIdOrUsername('twitterdev', \Noweh\TwitterApi\Enum\Modes::username) //OR \Noweh\TwitterApi\Enum\Modes::id

To Post a new Tweet

Example:

$return = $client->tweet()->performRequest('POST', ['text' => 'This is a test....']);

To Retweet

Example:

$return = $client->retweet()->performRequest('POST', ['tweet_id' => $tweet->id]);

Contributing

Fork/download the code and run

composer install

copy test/config/.env.example to test/config/.env and add your credentials for testing.

To run tests

./vendor/bin/phpunit

To run code analyzer

./vendor/bin/phpstan analyse .

twitter-api-v2-php's People

Contributors

noweh avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.