How to build an @anywhere application that will collect user data for putting into a database?

75 views
Skip to first unread message

impelmedia

unread,
Jul 22, 2011, 9:49:04 AM7/22/11
to Twitter Anywhere Development
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

Taylor Singletary

unread,
Jul 26, 2011, 3:11:33 PM7/26/11
to twitter-de...@googlegroups.com
My biggest recommendation to you is that if you're wanting to do any kind of persistence storage of data about Twitter users, you should use a server-to-server based integration rather than @Anywhere. I see that you're already using PHP and MySQL: this combination of technologies is best served by using server-to-server REST with OAuth instead of @Anywhere.

@episod - Taylor Singletary



--
Have you tried the Developer Discussions feature on https://dev.twitter.com/discussions yet?

Twitter developer links:
@anywhere documentation: https://dev.twitter.com/docs/anywhere/welcome
@anywhere updates via Twitter: https://twitter.com/anywhere

Unsubscribe or change your group membership settings: http://groups.google.com/group/twitter-dev-anywhere/subscribe

Reply all
Reply to author
Forward
0 new messages