PHP oAuth总是返回代码400

时间:2012-06-19 12:42:55

标签: php oauth oauth-2.0 twitter-oauth tumblr

我正在连接到Tumblr(这与Twitter几乎完全相同)。 我一直到验证页面,验证应用程序,然后返回到previos页面,所有正确的东西都在查询字符串上,但我在API文档上得到400错误说这意味着“无效”输入数据“。

这是我的代码:

        require("tumblr/tumblroauth/tumblroauth.php");
        // Enter your Consumer / Secret Key:
        $consumer   = $conf['Tumblr']['consumer'];
        $secret     = $conf['Tumblr']['secret'];
        /* Start session and load lib */
        if(!isset($_REQUEST['oauth_token']))
        {
            // Start the Session
            session_start();
            $connection = new TumblrOAuth($conf['Tumblr']['consumer'], $conf['Tumblr']['secret']);
                    // this url is correct
            $url = "http://" . $_SERVER['HTTP_HOST']  . $_SERVER['REQUEST_URI'];
            $temporary_credentials = $connection->getRequestToken($url);
            $redirect_url = $connection->getAuthorizeURL($temporary_credentials, FALSE);

            echo "going to".$redirect_url; // looks good
                    //have to use this as headers have started
            echo '<script>window.location.href="'.$redirect_url.'";</script>';
        }

        /* If the oauth_token is old redirect to the connect page. */
        if (isset($_REQUEST['oauth_token']) && $_SESSION['oauth_token'] !== $_REQUEST['oauth_token']) {
          $_SESSION['oauth_status'] = 'oldtoken';
          session_destroy();
        }
        if(isset($_REQUEST['oauth_token']))
        {/* Create TumblroAuth object with app key/secret and token key/secret from default phase */
            $connection = new TumblrOAuth($consumer, $secret, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);

            /* Request access tokens from tumblr */
            $access_token = $connection->getAccessToken($_REQUEST['oauth_verifier']);

            /* Save the access tokens. Normally these would be saved in a database for future use. */
            $_SESSION['access_token'] = $access_token;

            /* Remove no longer needed request tokens */
            unset($_SESSION['oauth_token']);
            unset($_SESSION['oauth_token_secret']);

            /* If HTTP response is 200 continue otherwise send to connect page to retry */
            if (200 == $connection->http_code) {
              /* The user has been verified and the access tokens can be saved for future use */
              $_SESSION['status'] = 'verified';
              echo 'connection made heres the code:<br/>'.$connection->http_code;
            } else {
              /* Save HTTP status for error dialog on connnect page.*/


                     // THIS IS ALWAYS BEING OUTPUT AT THE END
             echo "oh no something is wrong code:<br/>".$connection->http_code;
            }
        }

请有人看看我觉得我已经尝试过这个星球上的所有东西让它发挥作用.. ps使用:https://github.com/jacobbudin/tumblroauth

1 个答案:

答案 0 :(得分:0)

我认为你的问题在这里

    $redirect_url = $connection->getAuthorizeURL($temporary_credentials, FALSE);

尝试

    $redirect_url = $connection->getAuthorizeURL($temporary_credentials);

如果您仍然遇到问题,请告诉我们