无法处理此请求。 HTTP错误500 twitterOauth

时间:2018-10-16 05:41:32

标签: php oauth-2.0 twitter-oauth

我想通过php中的twitter Oauth获取用户时间。我在本地主机上执行了相同的代码,效果很好,但是当我在cpanel服务器上使用它时,出现此错误

www.varsitypartner.com is currently unable to handle this request.
HTTP ERROR 500 

我尝试获取解决方案以更正我的回叫网址和session_start()

我还在Twitter应用程序中添加了callbackurl,但bur错误仍然相同。

https://www.varsitypartner.com/twitter-login.php

twitter-login.php

<?php
// Include config file and twitter PHP Library
session_start();
include_once("config.php");
include_once("Oauth/twitteroauth/twitteroauth.php");

if(isset($_GET['request']))
{

        //Fresh authentication

        $connection = new TwitterOAuth(CONSUMER_KEY,CONSUMER_SECRET);

        $request_token = $connection->getRequestToken(OAUTH_CALLBACK);


        //Received token info from twitter
        $_SESSION['token']          = $request_token['oauth_token'];
        $_SESSION['token_secret']   = $request_token['oauth_token_secret'];

        //Any value other than 200 is failure, so continue only if http code is 200
        if($connection->http_code == '200')
        {
        //redirect user to twitter
        $twitter_url = $connection->getAuthorizeURL($request_token['oauth_token']);
        header('Location: ' . $twitter_url); 
        }else{
        die("error connecting to twitter! try again later!");
        }
}       $_SESSION['token_secret']   = $request_token['oauth_token_secret'];



?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Login with Twitter</title>

</head>
<body>
<?php
    if(isset($_REQUEST['oauth_token']) && $_SESSION['token'] == $_REQUEST['oauth_token']){

            $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['token'] , $_SESSION['token_secret']);
            $access_token = $connection->getAccessToken($_REQUEST['oauth_verifier']);
            if($connection->http_code == '200')
            {

                $user_data = $connection->get('account/verify_credentials'); 
                $result = '<h1>Twiiter Profile Details </h1>';
                $result .= '<img src="'.$user_data['profile_image_url'].'">';
                $result .= '<br/>Twiiter ID : ' . $user_data['id'];
                $result .= '<br/>Name : ' . $user_data['name'];
                $result .= '<br/>Twiiter Handle : ' . $user_data['screen_name'];
                $result .= '<br/>Follower : ' . $user_data['followers_count'];
                $result .= '<br/>Follows : ' . $user_data['friends_count'];
                $result .= '<br/>Logout from <a href="logout.php?logout">Twiiter</a>';
                echo '<div>'.$result.'</div>';              
            }else{
                   die("error, try again later!");
            }

    }else{
        //Display login button
        echo '<a href="twitter-login.php?request=twitter"><img src="images/login_button.jpg" /></a>';
    }
?>  

</body>
</html>

config.php

define('CONSUMER_KEY', 'xxxxx'); // YOUR CONSUMER KEY
define('CONSUMER_SECRET', 'xxxxx'); //YOUR CONSUMER SECRET KEY
define('OAUTH_CALLBACK', 'https://www.varsitypartner.com/twitter-login.php');  // Redirect URL
我的Twitter应用程序上的

callbackurl是:

https://www.varsitypartner.com/twitter-login.php
https://varsitypartner.com/twitter-login.php
https://www.varsitypartner.com/twitter-login.php?request=twitter

0 个答案:

没有答案