J7mbo / twitter-api-php

The simplest PHP Wrapper for Twitter API v1.1 calls
MIT License
1.82k stars 802 forks source link

Send Tweet #235

Closed ghost closed 7 years ago

ghost commented 7 years ago

Hello, Does anyone have a quick snippet of code that I could use to send a tweet?

J7mbo commented 7 years ago

Hi, there are tests showing different usages of the SDK.

Ignore media_ids as you're not uploading any media.

ghost commented 7 years ago

Does this look Correct? <?php

namespace Inactive-to-Reactive;

use pocketmine\plugin\PluginBase; use TwitterAPIExchange;

class Inactive-to-ReactiveExample extends PluginBase{

      public function onLoad(){
                $this->getLogger()->info("Plugin Loading");
      }
      public function onEnable(){
                $this->getLogger()->info("Enabled Plugin");

    $url    = 'https://api.twitter.com/1.1/statuses/update.json';

    $method = 'POST';

    $params = array(

        'status' => 'TEST TWEET TO BE DELETED' . rand(),

        'possibly_sensitive' => false,

        'media_ids' => self::$mediaId

    );

    $data     = $this->exchange->request($url, $method, $params);

    $expected = 'TEST TWEET TO BE DELETED';

    $this->assertContains($expected, $data);

    /** Store the tweet id for testStatusesDestroy() **/

    $data = @json_decode($data, true);

    $this->assertArrayHasKey('id_str', is_array($data) ? $data : array());

    self::$tweetId = $data['id_str'];

    /** We've done this now, yay **/

    self::$mediaId = null;

      }
      public function onDisable(){
                $this->getLogger()->info("Plugin Disabled");
      }

}

ghost commented 7 years ago

https://gist.github.com/NFGamerMC/554fdb93f16313ce20610fd265422786

Thunder33345 commented 7 years ago

should work i doubt the static self part should but in terms of sending it should in theory do it also ps, next time when you try to ask others about your code, try to do it in vanilla PHP, you cant expect everyone to know what pocketmine even is