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 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题