Hi all,
I’ve been banging my head against this for days now, and simply can’t find an easy-to-follow resource on it, and for the life of me, can’t get it working.
Has anybody got a simple, easy-to-follow, step by step, guide on how to integrate Twitter’s Oauth into my site?
I’ve loaded Elliot Haughin’s CI Library for Twitter & Oauth.
Here’s my controller (twitter_call.php):
<?php
class Twitter_call extends Controller {
//Could store these in the config etc, up to you
private $_consumer_key = 'lkdfjvhp9vhpvfndvdf'; // This has been changed, the actual controller has the correct key in there
private $_consumer_secret = 'lkdfjvhp9vhpvfndvdf'; // This has been changed, the actual controller has the correct secret in there
private $_access_token = ''; // I'm not sure what to put in here
private $_secret_access_token = ''; // I'm not sure what to put in here
function __construct() {
parent::Controller();
}
function index() {
$this->load->library('twitter');
$this->twitter->oauth($this->_consumer_key, $this->_consumer_secret, $this->_access_token, $this->_secret_access_token);
$data['tweets'] = $this->twitter->call('statuses/user_timeline');
//Load this data into a view and show it.
$this->load->view('twitter', $data);
}
}
and here’s my view(twitter.php):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php print_r($tweets); ?>
</body>
</html>
Here’s my .htaccess:
<IfModule mod_rewrite.c>
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
What I’ve done too:
Set $config[‘uri_protocol’] = “PATH_INFO”;
Set $config[‘permitted_uri_chars’] = ‘a-z? 0-9~%.:_\-’;
Now the problem I’m up against is - when I load http://www.mysite.com/twitter_call, the URL reverts to a login page where I log in to the app. If I re-set my $config[‘uri_protocol’] to AUTO, the login script for the app works, but I get no joy from the twitter code.
I just want to update my twitter status from this little app behind my site. This is driving me crazy, and my urge to type in capital letters is overwhelming…..! 😊
Can anyone help in a constructive manner? Referring me to Matt Willos site or Elliott Haughins site won’t really cut it
I can give someone access to my live code playground if needs be.
All info appreciated - thanks.
WoolyG