jublo / codebird-php

Easy access to the Twitter REST API, Direct Messages API, Account Activity API, TON (Object Nest) API and Twitter Ads API — all from one PHP library.
https://www.jublo.net/projects/codebird/php
GNU General Public License v3.0
775 stars 237 forks source link

Codebird PHP direct_message/new #253

Open xx461037 opened 4 years ago

xx461037 commented 4 years ago

I've been using Codebird for php for Twitter since it came out and now have version 3-1-5. With this I've been trying to develop a direct messaging app and seem to have a whole lot of problems I can not figure out how to fix, thus I need your input on how to solve these issues. Here is my code: public function __construct($CKey,$CPriv,$APIK, $APIP,$ForWho = null){ ob_start(); $this->twitter = new TwitterMessages($CKey,$CPriv,$APIK,$APIP,$ForWho); $SleepTime = 4900; if (ob_get_level() == 0) ob_start();
$this->ConsumerKey = $CKey; $this->ConsumerSec = $CPriv; $this->APIKey = $APIK; $this->APISec = $APIP; $this->ForWho = $ForWho; date_default_timezone_set('America/New_York'); }

public function SendDM($Resip,$MText,$URL,$PhotoID,$Lable){
    $Reply = $this->twitter->VerifyCredentials($Twitter->cb);
    if( $Reply->httpstatus == 200 ){
    $Param = [
        'event' => [
            'type' => 'message_create',
            'message_create' => [
                'target' => [
                        'recipient_id' => "$Resip"
                        ],
                        'message_data' => [
                        'text' => "$AdText",
                        ]
                        'attachment' => [
                            'type' => "media",
                            'media' => [
                               'id' => $PhotoID
                            ]
                        ]
                    ]
                ]
            ]
        ];            
       $reply = $this->twitter->cb->directMessages_events_new($Param);
        return $reply;
    }
    else{
        return FALSE;
    }
}

Within the code on the $reply I am always getting: code = 32 message = "Could not authenticate you." httpstatus = 401

From past experiences with this error I've realized that this means something is wrong with the way I am sending the request.

So can anyone help in this problem I am having?

Frank

xx461037 commented 4 years ago

I think I know where the problem is. In codebird, the function _getSignature breaks the array you send down to a string, but when you have a multidimensional array, which seems to be needed for Twitters new direct_messages/new command, codebird doesn't recognize the multidementions and for the event portion just gives blank array without any of the values within it.

I also tried using the old codebird/twitter version of direct_messages/new, which used a single dimensional array, and that came back with a 404 status and a 'Sorry that page doesn't exist'. Even though it does exist. Thus Twitter seems to expect a multidimensional array now.

xx461037 commented 4 years ago

It seems that this problem has been corrected in the new beta version of Codebird.

xx461037 commented 4 years ago

Note to all. When you want to do the direct message events new and use a picture do not use the media_category field. Even though you can use it to tweet a pic, I've found that for DM's it is not as useful.

mynetx commented 4 years ago

@xx461037 Any help with parsing a multidimensional array is appreciated! Can you write a test for it that will fail until we fixed it correctly?