Hi everyone!
I am having problems figuring out how to use the @anywhere application
to collect user information from the connected user to put into a
mysql database via php. I have set my callback URL in the application
settings and have tried using the following code:
session_start();
include_once("config.php");
include ('../connections/mysql_connect.php');
$oauthc = new OAuth($oauth['twitter']['consumerkey'],
$oauth['twitter']['consumersecret'],
OAUTH_SIG_METHOD_HMACSHA1,OAUTH_AUTH_TYPE_URI); //initiate
if(empty($_SESSION['trequest_token_secret'])) {
//get the request token and store it
$request_token_info = $oauthc->getRequestToken($oauth['twitter']
['requesttokenurl']); //get request token
$_SESSION['trequest_token_secret'] =
$request_token_info['oauth_token_secret'];
header("Location: {$oauth['twitter']['authurl']}?oauth_token=".
$request_token_info['oauth_token']);//forward user to authorize url
}
else if(empty($_SESSION['taccess_oauth_token'])) {
//get the access token - dont forget to save it
$request_token_secret = $_SESSION['trequest_token_secret'];
$oauthc->setToken($_REQUEST['oauth_token'],
$request_token_secret);//user allowed the app, so u
$access_token_info = $oauthc->getAccessToken($oauth['twitter']
['accesstokenurl']);
$_SESSION['taccess_oauth_token']=
$access_token_info['oauth_token'];
$_SESSION['taccess_oauth_token_secret']=
$access_token_info['oauth_token_secret'];
}
if(isset($_SESSION['taccess_oauth_token'])) {
//now fetch current users profile
$access_token = $_SESSION['taccess_oauth_token'];
$access_token_secret =$_SESSION['taccess_oauth_token_secret'];
$oauthc->setToken($access_token,$access_token_secret);
$data = $oauthc->fetch('
http://twitter.com/account/
verify_credentials.json');
$response_info = $oauthc->getLastResponse();
$userinfo = (json_decode($response_info,true));
$name = $userinfo['name'];
$twittername = $userinfo['screen_name'];
mysql_select_db($database_connect,$connect);
$insert_query = "INSERT INTO users (twitteruser, name) VALUES
('$twittername', '$name')";
$insert = mysql_query($insert_query,$connect) or die (mysql_error());
}
but it just doesn't work! I am totally new to the twitter integration
with a website for registration/connection purposes and I have really
been struggling...can anyone help me out?!
Thanks in advance
Rachel