2016-02-26 41 views
0

我使用这个twitter oAuth库(https://github.com/abraham/twitteroauth)和以下内容来实现它。此代码(称为testing.php)将用户引导至Twitter身份验证页面,然后返回授权令牌并返回有关其帐户的一些信息。很棒。用于Twitter的HTML/jQuery客户端和PHP后端oAuth

<?php 
session_start(); 
require_once ('twitteroauth/autoload.php'); 
$consumer_key = 'XXXXXXXXX'; 
$consumer_secret = 'XXXXXXXXX'; 
$callback = "http" . (($_SERVER['SERVER_PORT'] == 443) ? "s://" : "://") . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; 
if (isset($_SESSION['oauth_token'])) { 
    $oauth_token = $_SESSION['oauth_token']; 
    unset($_SESSION['oauth_token']); 
    $connection = new Abraham\TwitterOAuth\TwitterOAuth($consumer_key, $consumer_secret); 
    $params = array("oauth_verifier" => $_GET['oauth_verifier'], 'oauth_token' => $_GET['oauth_token']); 
    $access_token = $connection->oauth('oauth/access_token', $params); 
    $connection = new Abraham\TwitterOAuth\TwitterOAuth($consumer_key, $consumer_secret, $access_token['oauth_token'], $access_token['oauth_token_secret']); 
    $content = $connection->get('account/verify_credentials'); 
    print_r($content); 
} else { 
    $connection = new Abraham\TwitterOAuth\TwitterOAuth($consumer_key, $consumer_secret); 
    $temporary_credentials = $connection->oauth('oauth/request_token', array("oauth_callback" => $callback)); 
    $_SESSION['oauth_token'] = $temporary_credentials['oauth_token']; 
    $_SESSION['oauth_token_secret'] = $temporary_credentials['oauth_token_secret']; 
    $url = $connection->url('oauth/authenticate', array('oauth_token' => $temporary_credentials['oauth_token'])); 
    header('Location: ' . $url); 
} 

不过,我想建立使用HTML和JavaScript/jQuery的(index.html的),而不是PHP(的index.php)我的前端。

我试着在这里调整回调并使用AJAX调用这个PHP,但由于交叉脚本的限制,我无法返回任何HTML。你怎么从HTML => => HTML验证页面=> HTML

谢谢。

回答

相关问题