Twitter OAUTH - 返回响应代码“0"; [英] Twitter OAUTH - returns response code of "0"

查看:77
本文介绍了Twitter OAUTH - 返回响应代码“0";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 Matt Harris 的 Twitter OAUTH 库 (https://github.com/themattharris/tmhOAuth) 用我的密钥和令牌替换默认数据,但由于某种原因我无法获得有效的响应代码.

I've tried using Matt Harris' Twitter OAUTH library (https://github.com/themattharris/tmhOAuth) replacing default data with my keys and tokens, but for some reason I can't get a valid response code.

我正在测试的 url 以端口 (8888) 结尾,但我不确定这是否与它有关.我正在跟踪 PHP 日志并且没有错误.

The url I'm testing with ends with a port (8888), but I'm not sure if that is to do with it. I'm tailing the PHP log and there are no errors.

$tweet_text = 'Hello world!';
print "Posting...\n";
$result = post_tweet($tweet_text);
print "Response code: " . $result . "\n";

function post_tweet($tweet_text) {

  require_once('tmhOAuth.php');

  $connection = new tmhOAuth(array(
    'consumer_key'    => '(hidden)',
    'consumer_secret' => '(hidden)',
    'user_token'      => '(hidden)',
    'user_secret'     => '(hidden)',
  )); 

  $connection->request('POST', 
    $connection->url('1/statuses/update'), 
    array('status' => $tweet_text));

  return $connection->response['code'];
}

有人有什么想法吗?

非常感谢.

推荐答案

我遇到了这个问题,这是由于 2011 年 12 月的这个最新变化造成的:

I had this problem and it's due to this recent change in December 2011:

默认 CURLOPT_SSL_VERIFYPEER 为真"

"defaulted CURLOPT_SSL_VERIFYPEER to true"

如果你按照 Darren 的建议转储 $connection->response,你可能会看到一个错误,比如我遇到的这个错误:

If you dump $connection->response as Darren advises, you may see an error such as this one which I had:

string(165) "错误设置证书验证位置:"

string(165) "error setting certificate verify locations:"

要么确保证书文件 cacert.pem 就位,要么禁用 SSL_VERIFYPEER.

Either make sure that the certificate file cacert.pem is in place, or disable SSL_VERIFYPEER.

我敢打赌这会解决您的问题(尽管它可能不是最安全的解决方案):

I'm willing to bet that this will fix your issue (although it may not be the most secure solution):

$connection = new tmhOAuth(array(
    'consumer_key'          => '(hidden)',
    'consumer_secret'       => '(hidden)',
    'user_token'            => '(hidden)',
    'user_secret'           => '(hidden)',
    'curl_ssl_verifypeer'   => false
));

2015 年 2 月更新

今天回顾这个答案,我意识到建议人们将 curl_ssl_verifypeer 设置为 false 并不是一个很好的答案(此时你不能再确定自己是在与 Twitter 交谈,所以实际上这是一个糟糕的答案).相反,请采纳我给出的其他建议并确保适当的根 CA 证书文件 (cacert.pem) 到位.

Looking back on this answer today, I realise that advising people to set curl_ssl_verifypeer to false is not a very good answer (at this point you can no longer be sure you're talking to Twitter, so in fact it's a terrible answer). Instead, take the other advice I gave and ensure the appropriate Root CA Certificate file (cacert.pem) is in place.

这篇关于Twitter OAUTH - 返回响应代码“0";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆