Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codebird PHP direct_message/new #253

Open
xx461037 opened this issue Aug 21, 2019 · 4 comments
Open

Codebird PHP direct_message/new #253

xx461037 opened this issue Aug 21, 2019 · 4 comments

Comments

@xx461037
Copy link

xx461037 commented Aug 21, 2019

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
Copy link
Author

xx461037 commented Aug 22, 2019

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
Copy link
Author

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

@xx461037
Copy link
Author

xx461037 commented Sep 1, 2019

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
Copy link
Member

mynetx commented Sep 1, 2019

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants