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

Direct message new API returning NULL #714

Closed
hlashish opened this Issue Sep 16, 2018 · 15 comments

Comments

Projects
None yet
5 participants
@hlashish

hlashish commented Sep 16, 2018

Hi Sir

I am using the following code and library functions to use twitter API's

require "vendor/autoload.php";

use Abraham\TwitterOAuth\TwitterOAuth;
$consumerKey 					= 'vT********************RQy';
$consumerSecret 				= 'hdJqg*****************o************************MF0';
$accessToken 					= "8**********************************************a6I";
$accessSecret 					= "zYJ********************************************dRH";
$baseUrl 						=  "http://******************/";
$redirectURL 					= 'http://******************/';


$connection = new TwitterOAuth($consumerKey, $consumerSecret, $accessToken, $accessSecret);
$content = $connection->get("account/verify_credentials");
$connection->setTimeouts(10, 15);
echo "<pre>"; print_r($content);echo "</pre>"; 
$userId = "1027************96 ";

 $userDtaRes = $connection->get('users/lookup ', array('screen_name' => "Easemymarketing")); 
 print_r("<br/> user lookup API <br/>");
var_dump("<br/>".$connection->getLastHttpCode());
var_dump("<br/>".$connection->getLastApiPath());
var_dump("<br/>".$userDtaRes);



$data = [
    'event' => [
        'type' => 'message_create',
        'message_create' => [
            'target' => [
                'recipient_id' => $userId
            ],
            'message_data' => [
                'text' => "hi new dm messg to ashsi "
            ]
        ]
    ]
];

$result = $connection->post('direct_messages/events/new ', $data, true); // Note the true
print_r("<br/> USER send direct mesage api <br/>");
var_dump("<br/>".$connection->getLastHttpCode());

var_dump("<br/>".$result);

Always it returns NULL for each library, please guide me how to run the to fetch various API result and send the direct message event new.

@hlashish

This comment has been minimized.

hlashish commented Sep 16, 2018

I am attaching the #screen-shot of app permissions and browser result for further refrence -::

app-permisions

@abraham

This comment has been minimized.

Owner

abraham commented Sep 16, 2018

Try var_dump($userDtaRes); and var_dump("<br/>".$result); without the "<br/>". because is going to try and concatenate the complex object with the string which is going to be a bad time.

@hlashish

This comment has been minimized.

hlashish commented Sep 17, 2018

Try var_dump($userDtaRes); and var_dump("<br/>".$result); without the "<br/>". because is going to try and concatenate the complex object with the string which is going to be a bad time.

Hi
I tried var_dump($userDtbaRes); but it is still returning null, can you please help me out also what about the deirect new messsage create event api it is aso not working even after app permissons

@abraham

This comment has been minimized.

Owner

abraham commented Sep 20, 2018

I don't see any obvious reasons why this wouldn't work. Two things that to check is that you are using the latest version of TwitterOAuth and that the person you are sending the DM to has authorized the sender to contact them.

@ozgurky

This comment has been minimized.

ozgurky commented Sep 26, 2018

There is a space end of new message endpoint, checking actual code for this space can be helpful maybe. Also this space exists in the JSON data part of https://twitteroauth.com/ main page doc.

$result = $connection->post('direct_messages/events/new ', $data, true); // Note the true

@abraham

This comment has been minimized.

Owner

abraham commented Sep 26, 2018

Ya, the extra space at the end of the path will likely cause issues.

@hlashish

This comment has been minimized.

hlashish commented Sep 30, 2018

I have removed the extra space still the same issue exists, do anyone is still facing the null return value issue (👎

@abraham

This comment has been minimized.

Owner

abraham commented Oct 2, 2018

I just copied the code you have and there are multiple places with with trailing spaces. After fixing them sending direct messages worked fine.

$userDtaRes = $connection->get('users/lookup ', array('screen_name' => "Easemymarketing"));

$userId = "1027************96 ";

$result = $connection->post('direct_messages/events/new ', $data, true);

@abraham abraham added the Waiting on label Oct 2, 2018

@CesarNatic

This comment has been minimized.

CesarNatic commented Oct 3, 2018

I have removed the extra space still the same issue exists, do anyone is still facing the null return value issue (-1

Im facing the same issue.

require_once(APP.'Vendor/twitteroauth/twitteroauth/twitteroauth.php');
      $tweet = new TwitterOAuth('**********************************',
        '***********************************************',
        $tokenTwitter['Socialtoken']['access_token'],
        $tokenTwitter['Socialtoken']['access_token_secret']);     
      $mensaje = '123';
      $userDtaRes = $tweet->get('users/lookup', array('screen_name' => $nombreUsuario)); 
      $idusr = $userDtaRes[0]->id_str;     
      $text = 'DM ' . $nombreUsuario . ' ' . $mensaje;
 
      $data = [
          'event' => [
              'type' => 'message_create',
              'message_create' => [
                  'target' => [
                      'recipient_id' => $idusr
                  ],
                  'message_data' => [
                      'text' => $text
                  ]
              ]
          ]
      ];

     // var_dump($data);die;
    
      $tw = $tweet->post('direct_messages/events/new', $data, true);  
      if(isset($tw->sender)){
        CakeLog::write('twitterDM', "Twit enviado a " . $nombreUsuario, 'twitterDM');
      }
      if(isset($tw->errors)){
         CakeLog::write('twitterDM', "Error al enviar a " . $nombreUsuario . " por CODE: {$tw->errors[0]->code} mensaje: {$tw->errors[0]->message}", 'twitterDM');
      }
      
      debug($tw);die;

$data is correct, but $tw returns null, if i put the old endpoint i get a response from the twitter api but if i put the new endpoint i get a null and this error:

Array to string conversion [APP/Vendor/twitteroauth/twitteroauth/twitteroauth.php, line 223]

@hlashish

This comment has been minimized.

hlashish commented Oct 3, 2018

HI @abraham

Thanks for all the help and time you invested for my code debugging. It started working now.

Again thanks a lot for all your help and cooperation :)

@hlashish hlashish closed this Oct 3, 2018

@CesarNatic

This comment has been minimized.

CesarNatic commented Oct 3, 2018

HI @abraham

Thanks for all the help and time you invested for my code debugging. It started working now.

Again thanks a lot for all your help and cooperation :)

What you did to solve it?

@abraham

This comment has been minimized.

Owner

abraham commented Oct 3, 2018

@CesarNatic this API is only supported in version 0.9 and later.

@CesarNatic

This comment has been minimized.

CesarNatic commented Oct 4, 2018

Thanks so much @abraham, updated to last version and worked like butter. :) Nice library btw.

@awadhajj

This comment has been minimized.

awadhajj commented Nov 14, 2018

Am using 0.9.2, and still receiving NULL response!
`

    $tw_con = $this->twConnect();

    $statues = $tw_con->post("statuses/update", array("status" => '.......'));
    echo $tw_con->getLastHttpCode();
    print_r($statues);
    $data = [
            'event' => [
                'type' => 'message_create',
                'message_create' => [
                    'target' => [
                        'recipient_id' => '872***********304' //$y->id
                    ],
                    'message_data' => [
                        'text' => 'Hi am just testing some service'
                    ]
                ]
            ]
        ];
  
        $result = $tw_con->post('direct_messages/events/new ', $data, true); 
        echo $tw_con->getLastHttpCode();
        var_dump($result);

`
the "post status" in the second line works well, but the 'post direct msg' not working

am sending to a user that following me, and i always contact him through Direct Meassage :(

@abraham

This comment has been minimized.

Owner

abraham commented Nov 17, 2018

@awadhajj Your API path string has a space in it 'direct_messages/events/new '

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