无法使用亚伯拉罕的TwitterOAuth for PHP获取令牌; HTTP 500返回

时间:2015-05-10 03:08:57

标签: php twitter oauth twitter-oauth

我正在尝试将@abraham's TwitterOAuth 0.5.3库用于PHP,但是当我请求3-legged authorization的令牌时,我会收到一个HTTP 500作为响应。

以下是我在PHP中设置代码的方法:

<?php

/* Start session and load library. */
session_start();

require_once('config.php');

require_once('twitteroauth/autoload.php');
use Abraham\TwitterOAuth\TwitterOAuth;

/* Build TwitterOAuth object with client credentials. */
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);

/* Get temporary credentials. */
// Error occurs on the following line, unable to dump $request_token 
$request_token = $connection->oauth('oauth/request_token', array('oauth_callback' => OAUTH_CALLBACK));

//print_r($request_token); // <-- Never reached!!

我知道这个问题不在Twitter API中,因为我已经确认我可以通过Dev console访问我的Twitter帐户。

此外,我已经在某种程度上验证了TwiterOAuth库的工作原理,方法是遵循库提供的Authorization flow example。该示例还可以访问我的Twitter帐户。

我无法弄清楚发生了什么,因为我无法正确授权我的PHP应用程序访问我的Twitter帐户。

我做错了什么?

1 个答案:

答案 0 :(得分:0)

我的问题以另一种方式解决了。在检查(根据 jhenderson2099 的答案)我的主机是否启用了 curl_exec 之后(确实如此)。我发现我的问题是由 src/TwitterOauth.php(TwitterOauth 类)中的两行引起的:

$bundlePath = CaBundle::getSystemCaRootBundlePath(); <-- Comment this line
$options = [
        // CURLOPT_VERBOSE => true,
        CURLOPT_CONNECTTIMEOUT => $this->connectionTimeout,
        CURLOPT_HEADER => true,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_SSL_VERIFYHOST => 2,
        CURLOPT_SSL_VERIFYPEER => true,
        CURLOPT_TIMEOUT => $this->timeout,
        CURLOPT_USERAGENT => $this->userAgent,
        $this->curlCaOpt($bundlePath) => $bundlePath,<-- Comment this line
    ];

让你的代码看起来像这样:

//$bundlePath = CaBundle::getSystemCaRootBundlePath();
        $options = [
            // CURLOPT_VERBOSE => true,
            CURLOPT_CONNECTTIMEOUT => $this->connectionTimeout,
            CURLOPT_HEADER => true,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_SSL_VERIFYHOST => 2,
            CURLOPT_SSL_VERIFYPEER => true,
            CURLOPT_TIMEOUT => $this->timeout,
            CURLOPT_USERAGENT => $this->userAgent,
            //$this->curlCaOpt($bundlePath) => $bundlePath,
        ];
相关问题