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

New APIs for messages #651

Closed
3RLikeNoOther opened this Issue May 18, 2018 · 9 comments

Comments

Projects
None yet
6 participants
@3RLikeNoOther

3RLikeNoOther commented May 18, 2018

Hi,
as you may know Twitter will change APIs for managing messages.
At the moment I'm trying the one to send a message:
https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/new-event
Using the code below I get null as result.
Is my code wrong or the library doesn't support these new APIs?
Thanks

$connection = new TwitterOAuth( ... );

$parameters = array(
    'event' => array(
        'type' => "message_create",
        'message_create' => array(
            'target' => array(
                'recipient_id' => 306993015
            ),
            'message_data' => array(
                'text' => "Hello world"
            )
        )
    )
);

$result = $connection->post("direct_messages/events/new", $parameters);

echo json_encode($result,JSON_PRETTY_PRINT);
@pklosko

This comment has been minimized.

pklosko commented May 23, 2018

Hi, my piggy quick hack due to new API is:

diff src/TwitterOAuth.orig.php src/TwitterOAuth.php
406c406,410
<         $request = Request::fromConsumerAndToken($this->consumer, $this->token, $method, $url, $parameters);
---
>         if (count($parameters) > 1){
>           $request = Request::fromConsumerAndToken($this->consumer, $this->token, $method, $url, $parameters);
>         }else{
>           $request = Request::fromConsumerAndToken($this->consumer, $this->token, $method, $url);
>         }
483a488
>                 if (count($postfields) > 1){
484a490,493
>                 }else{
>                   $options[CURLOPT_POSTFIELDS] = $postfields[0];
>                   $options[CURLOPT_HTTPHEADER] = ['Accept: application/json', $authorization, 'Expect:', 'Content-Type: application/json','Content-Length: ' . strlen($postfields[0])];
>                 }

and call

...
  $msg   = $connection->post('direct_messages/events/new', array(json_encode($parameters)));

where $parameters is an array mentoined in 3RLikeNoOther's post

P.

@Langsdorf

This comment has been minimized.

Langsdorf commented May 26, 2018

Thank you!! @pklosko

@JosephShenton

This comment has been minimized.

JosephShenton commented May 27, 2018

Hi @pklosko do you mind creating a fork with your changes please? I do not understand where these changes go.

@Langsdorf

This comment has been minimized.

Langsdorf commented May 27, 2018

@JosephShenton see TwitterOAuth.php

private function oAuthRequest($url, $method, array $parameters)

private function request($url, $method, $authorization, array $postfields)

@JosephShenton

This comment has been minimized.

JosephShenton commented May 27, 2018

@pklosko

This comment has been minimized.

pklosko commented May 28, 2018

@JosephShenton
Sorry. I'm out of PC.
OK I'll do it.
Probably during next week

@pklosko

This comment has been minimized.

@derikb

This comment has been minimized.

derikb commented Jun 29, 2018

Would love it if a fix for this could get into a release. That Twitter DM API change is coming up in August and I'd hate to have to try some workaround.

@abraham

This comment has been minimized.

Owner

abraham commented Jul 3, 2018

This is now available in v0.9

@abraham abraham closed this Jul 3, 2018

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