danieldevine/bird-elephant

Issue in Direct message without attachments

Closed this issue · 2 comments

Describe the bug
While sending a dm to a particular user without attachments I am getting the below error.

stdClass Object
(
    [errors] => Array
        (
            [0] => stdClass Object
                (
                    [parameters] => stdClass Object
                        (
                            [$.attachments] => Array
                                (
                                    [0] => null
                                )

                        )

                    [message] => $.attachments: null found, array expected
                )

        )

    [title] => Invalid Request
    [detail] => One or more parameters to your request was invalid.
    [type] => https://api.twitter.com/2/problems/invalid-request
)

this is because attachments are sent to Twitter by default even if we send just DM.

coderjerk\bird-elephant\src\Compose\DirectMessage.php
in this above class attachments variable from line 8 is declared as a string. Declaring this as an array worked for me.

I think that is the issue. Please debug and fix the issue.

To Reproduce

$twitter = new BirdElephant(['bearer_token' => $res['bearer_token'],
                'consumer_key' => $res['consumer_key'],'consumer_secret' => $res['consumer_secret'],'token_identifier' => $res['access_key'],'token_secret' => $res['access_secret']]);
            $dms = $twitter->directMessages();
            $dm = (new \Coderjerk\BirdElephant\Compose\DirectMessage)->text('Hello Buddy');
            // echo "<pre>";print_r($dm);exit;
            $res = $dms->message($dm)->sendTo('madforcryptos_');

echo "<pre>";print_r($res);exit;

Environment (please complete the following information):

  • Windows
  • php version: 7.4.3
  • Bird Elephant version: ^0.6.0

fixed in 0.6.1

Thanks, daniel, working fine