Reputation: 10686
I tried to post tweets using this opensource API. I have created Twitter App and received all needed keys (4 keys). So I don't understand why my script is wrong.
ini_set('display_errors', 1);
require_once("libs/twitter/TwitterAPIExchange.php");
/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
$settings = array(
'oauth_access_token' => "...",
'oauth_access_token_secret' => "...",
'consumer_key' => "...",
'consumer_secret' => "..."
);
$url = "https://api.twitter.com/1.1/statuses/update.json";
$requestMethod = 'POST';
/** POST fields required by the URL above. See relevant docs as above **/
$postfields = array(
'status' => 'Hi, I am new status from Social Poster!'
);
/** Perform a POST request and echo the response **/
$twitter = new TwitterAPIExchange($settings);
$result = $twitter->buildOauth($url, $requestMethod)
->setPostfields($postfields)
->performRequest();
var_dump($result);
var_dump
shows false.
Upvotes: 0
Views: 270
Reputation: 289
I know this is an old post, but just for anyone who is having the same problem, here is the solution:
In your TwitterAPIExchange.php
file, go to the performRequest
method and change your $options
variable from
$options = array(
CURLOPT_HTTPHEADER => $header,
CURLOPT_HEADER => false,
CURLOPT_URL => $this->url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 10,
);
to this:
$options = array(
CURLOPT_HTTPHEADER => $header,
CURLOPT_HEADER => false,
CURLOPT_URL => $this->url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false, //this is what you need to add
CURLOPT_TIMEOUT => 10,
);
Upvotes: 1