2014-11-03 177 views
0

我试图使用此opensource API发布推文。我创建了Twitter应用程序并收到了所有需要的密钥(4个密钥)。所以我不明白我的脚本为什么是错的。Twitter API始终返回false

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显示

+0

是什么错误? – 2014-11-03 14:55:19

+0

根本不起作用,没有错误,只有在响应结果中不存在异常。 – 2014-11-03 15:31:49

回答

1

我知道这是一个古老的职位,但只是谁是有同样的问题的人,这里是解决方案:

在你TwitterAPIExchange.php文件,转到performRequest方法和你$options变量从

改变
$options = array( 
     CURLOPT_HTTPHEADER => $header, 
     CURLOPT_HEADER => false, 
     CURLOPT_URL => $this->url, 
     CURLOPT_RETURNTRANSFER => true, 
     CURLOPT_TIMEOUT => 10, 
    ); 

这样:

$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, 
    ); 
+0

谢谢,它真的帮助我:) – mibrito 2016-09-01 17:43:26