dsklzerpx64815631 2015-07-06 12:44 采纳率: 100%
浏览 187
已采纳

TwitterOAuth实现错误代码215:错误的身份验证数据

I'm receiving a TwitterOAuthException when trying to implement a request_token & replicating the functionality of TwitterOAuth.

The error

The code I am using is as follows:

require_once $cfg['server']['root']."/inc/lib/tw/autoload.php";

use Abraham\TwitterOAuth\TwitterOAuth;

define('CONSUMER_KEY', getenv('SlUlxP1lmXqqCCqoUOy0DGAL6'));
define('CONSUMER_SECRET', getenv('MM0vL2aRwp9rgS7qUF8UNEO3NtYv9W7QCZYSDzAyrZt7qa0XGg'));
define('OAUTH_CALLBACK', getenv('http://www.example-site.com/login/'));

$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
pA($connection); //print connection contents

$request_token = $connection->oauth('oauth/request_token', array('oauth_callback' => OAUTH_CALLBACK));

pA($request_token); //print connection contentsa

The output I get is:

Abraham\TwitterOAuth\TwitterOAuth Object
(
    [response:Abraham\TwitterOAuth\TwitterOAuth:private] => Abraham\TwitterOAuth\Response Object
        (
            [apiPath:Abraham\TwitterOAuth\Response:private] => 
            [httpCode:Abraham\TwitterOAuth\Response:private] => 0
            [headers:Abraham\TwitterOAuth\Response:private] => Array
                (
                )

            [body:Abraham\TwitterOAuth\Response:private] => Array
                (
                )

            [xHeaders:Abraham\TwitterOAuth\Response:private] => Array
                (
                )

        )

    [bearer:Abraham\TwitterOAuth\TwitterOAuth:private] => 
    [consumer:Abraham\TwitterOAuth\TwitterOAuth:private] => Abraham\TwitterOAuth\Consumer Object
        (
            [key] => 
            [secret] => 
            [callbackUrl] => 
        )

    [token:Abraham\TwitterOAuth\TwitterOAuth:private] => 
    [signatureMethod:Abraham\TwitterOAuth\TwitterOAuth:private] => Abraham\TwitterOAuth\HmacSha1 Object
        (
        )

    [timeout:protected] => 5
    [connectionTimeout:protected] => 5
    [decodeJsonAsArray:protected] => 
    [userAgent:protected] => TwitterOAuth (+https://twitteroauth.com)
    [proxy:protected] => Array
        (
        )

)

Fatal error: Uncaught exception 'Abraham\TwitterOAuth\TwitterOAuthException' with message '{"errors":[{"code":215,"message":"Bad Authentication data."}]}' in /home/user/public/test.com/public/inc/lib/tw/src/TwitterOAuth.php:137 Stack trace: #0 /home/chrismoore/public/trybe-ing.com/public/login/tw/tw_header.php(13): Abraham\TwitterOAuth\TwitterOAuth->oauth('oauth/request_t...', Array) #1 /home/user/public/test.com/public/login/index.php(6): require_once('/home/user...') #2 {main} thrown in /home/user/public/test.com/public/inc/lib/tw/src/TwitterOAuth.php on line 137

Can anyone help me find a solution to this problem.

Thanks.

  • 写回答

1条回答 默认 最新

  • dtxzwdl08169 2015-07-06 13:03
    关注

    getenv() looks for an environment variable with the name passed as a string argument. But it looks like you've passed the values you intend to use to getenv(). (by the way, if this is true, probably best not to put your secret in plaintext on a public website?)

    Have you tried just passing those strings as the second argument to define(), without wrapping in getenv()?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀