开发者

What is wrong with this twitter authentication

开发者 https://www.devze.com 2023-03-20 12:10 出处:网络
I have this code, but its not executing. require_once(\'twitterOAuth.php\'); session_start(); // The TwitterOAuth instance

I have this code, but its not executing.

require_once('twitterOAuth.php');
session_start();

// The TwitterOAuth instance
$twitteroauth = new TwitterOAuth('consumerkey', 'consumersecret');
// Requesting authentication tokens, the parameter is the URL we will be redirected to
$request_token = $twitteroauth->getRequestToken('http://localhost/tweet/twitterOAuth.php');

// Saving them into the session
$_SE开发者_StackOverflow社区SSION['oauth_token'] = $request_token['oauth_token'];
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];

// If everything goes well..
if($twitteroauth->http_code==200){
    // Let's generate the URL and redirect
    $url = $twitteroauth->getAuthorizeURL($request_token['oauth_token']);
    header('Location: '. $url);
} else {
    // It's a bad idea to kill the script, but we've got to know when there's an error.
    die('Something wrong happened.');
}

Any reasons as to why?


Twitter Oauth libraries and APIs do not work with localhost URLs. You have to register your application with Twitter against a real URL and not localhost URLs.

You should probably use some hosting service like Bluehost and then register your application against a URL.There is apparently another way set up a virtual host which i haven't tried personally. But you can give it a try. I am not very sure it works.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号