Tweet image along with the text, PHP Not working now


#1

I am using twitter api to tweet image along with the text, before it was working fine but suddenly it is showing blank page on callback.php file. Below is the code I am using please help me in fixing this.

    <?php
    
      require 'config.php';
      require 'tmhOAuth.php';
      require 'tmhUtilities.php';
      
      /// retrive temp access token from cookie 
        $token = $_COOKIE['Temp_Token'];
        $secret = $_COOKIE['Temp_Secret'];
        $img = $_COOKIE['Img_Url'];
        $txt = $_COOKIE['Tweet_Txt'];
      
      
      $tmhOAuth = new tmhOAuth(array(
       'consumer_key'    => API_KEY,
        'consumer_secret' => API_SEC,
        'user_token'      => $token,
        'user_secret'     => $secret,	
        'curl_ssl_verifypeer'   => false
      ));
      
        /// Ask Twitter for correct access token 
       
       $tmhOAuth->request("POST", $tmhOAuth->url("oauth/access_token", ""), array(  
            // pass the oauth_verifier received from Twitter  
            'oauth_verifier'    => $_GET["oauth_verifier"], 'oauth_token' => 	$_GET["oauth_token"]	
        )); 
    	
        $response = $tmhOAuth->extract_params($tmhOAuth->response["response"]);
    	$tmhOAuth->config["user_token"] = $response['oauth_token'];  
        $tmhOAuth->config["user_secret"] = $response['oauth_token_secret']; 
        
       $code = $tmhOAuth->request('POST', 'https://api.twitter.com/1.1/statuses/update_with_media.json', array('media[]'  => "@{$img}", 'status'   => "$txt"), true, true);
      
    print_r($code);
     
    if ($code == 200){
           tmhUtilities::pr(json_decode($tmhOAuth->response['response']));
    	  echo '<h1>Your image tweet has been sent successfully</h1>';
        }else{
          // display the error 
    	  tmhUtilities::pr($tmhOAuth->response['response']);
        }
        
    	
    
    
    
    ?>

displaying output is zero. I am unable to find where exactly the problem is. Thanks in advance


#2

Please some can tell me, Is this twitter api is working?


#3

Not sure whether you’ve seen the other thread about media uploads, but the update_with_media update endpoint is deprecated and we are moving to the dedicated upload endpoint. Apparently the codebird PHP library works well with this.


#4

Hi Andypiper, Thank you for your reply. Where I can check “moving to the dedicated upload endpoint” when it is done. Thank once again.


#5

You can learn more about uploading media in our docs.