Error trying to perform retweet using TwitterAPIExchange.php

1

Error trying to perform retweet using TwitterAPIExchange.php I try to occupy this code:

<?php
 ini_set('display_errors', 1);
 require_once('TwitterAPIExchange.php');


function RT($id){   
    $settings = array(
    'oauth_access_token' => 'xxxxxxx',
    'oauth_access_token_secret' => 'xxxxxx',
    'consumer_key' => 'xxxxxx',
    'consumer_secret' => 'xxxxxxxx',
     );

     $url = 'https://api.twitter.com/1.1/statuses/retweet/'.$id.'.json';
     $requestMethod = 'POST';
     $twitter = new TwitterAPIExchange($settings);
     return $twitter->buildOauth($url, $requestMethod)->performRequest();
}

echo RT("901856631855730689");
?>

This error appears when executing the code

  

{"errors": [{"code": 32, "message": "Could not authenticate you."}]}

Some idea of what the reason is.

    
asked by BotXtrem Solutions 28.09.2017 в 03:48
source

1 answer

0

After a bit of research I can find the answer:

 $url = 'https://api.twitter.com/1.1/statuses/retweet/'.$id_tweet.'.json';
 $postfields=array();
 $requestMethod = 'POST';
 $wp = array(CURLOPT_SSL_VERIFYPEER => false);
 $twitter = new TwitterAPIExchange($settings);
 $string = json_decode($twitter->setPostfields($postfields)
        ->buildOauth($url, $requestMethod)
        ->performRequest(true,$wp),$assoc = TRUE); 
 return($string['text']);

It's just a matter of adding the

  

setPostfields ($ postfields)

before

  

buildOauth

I hope it works for you as a reference Thank you

    
answered by 28.09.2017 / 06:44
source