I can not receive events in my webhook (it's empty)


#1

Hello,

I have managed to register my webhook url
POST https://api.twitter.com/1.1/account_activity/all/:env_name/webhooks.json

I have also been able to add subscribers
POST https://api.twitter.com/1.1/account_activity/all/:env_name/subscriptions.json

I have verified challenge response (CRC)
PUT https://api.twitter.com/1.1/account_activity/all/:env_name/webhooks/:webhook_id.json

I have activities in my account as: (Tweets, Retweets, @mentions, Favorite (like), Direct message).
The account activities reach my email but empty.
Example: Test [ ]

This is my code in the webhook to receive email

<?php

  $headers = apache_request_headers();

  $input_txt = file_get_contents('php://input');
  $input_txt = json_decode($input_txt);

   
  function send_email_twitter_activity($from_email,$to_email,$subject,$body)
  {
    $subject=utf8_encode($subject);
    $body=utf8_encode($body);

    $mailgun_url='URL email';
    $mailgun_key='xxxx'; 
    $from="<$from_email>";

    $array_data = array(
      'from'=> $from,
      'to'=>$send_email,
      'subject'=>$subject,
      'html'=>$body,
      'text'=>$body
    );

    $session = curl_init($mailgun_url);
      curl_setopt($session, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
      curl_setopt($session, CURLOPT_USERPWD, $mailgun_key);
      curl_setopt($session, CURLOPT_POST, true);
      curl_setopt($session, CURLOPT_POSTFIELDS, $array_data);
      curl_setopt($session, CURLOPT_HEADER, false);
      curl_setopt($session, CURLOPT_ENCODING, 'UTF-8');
      curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($session, CURLOPT_SSL_VERIFYPEER, false);
    $response = curl_exec($session);

    curl_close($session);
    $results = $response;
    return $results;

  }	

  $token  = $_REQUEST['crc_token'];
  $res    = $_REQUEST;
  $res = json_encode($res);

  send_email_twitter_activity("juan@hotmail.com","juan215@hotmail.com","Datos recibidos Profile","Test: $res");

   
  function get_challenge_response($token) {
    $APP_CONSUMER_SECRET = "YOUR_CONSUMER_SECRET";
    $hash = hash_hmac('sha256', $token, $APP_CONSUMER_SECRET, true);
    $response = array(
      'response_token' => 'sha256=' . base64_encode($hash)
    );
    header("HTTP/1.1 200 OK");
    header('Content-Type: application/json;charset=utf-8');
    return json_encode($response);
    exit();

  }
    
  // // prints result
  echo  get_challenge_response($token);

  print_r($res);
    
  print_r($headers);

closed #2

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.


opened #3

#4

Hi Juan - did you manage to get this sorted out?


#5

Hello,
Thanks for asking.
Yes, I already managed to solve the problem, I just needed these lines of code to work correctly.

$token = $_GET['crc_token'];

$input_txt = file_get_contents('php://input');
$input_txt = json_decode($input_txt,true);

json_encode($input_txt);

closed #6