CodeIgniter Forums
Twitter none oAuth request with Haughin library - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Twitter none oAuth request with Haughin library (/showthread.php?tid=38935)

Pages: 1 2


Twitter none oAuth request with Haughin library - El Forum - 02-23-2011

[eluser]SteRiley[/eluser]
I'm trying to use Elliot Haughin's Twitter library to make a request to the Twitter API that does not require oAuth as the information I'm after is just on a public timeline as explained here: http://dev.twitter.com/doc/get/statuses/user_timeline

I was hoping I could just do the following:
Code:
$user = $this->tweet->call('get', 'statuses/user_timeline', array('screen_name' => 'SteRiley'));
var_dump($user);

This however just causes an error when debug is enabled. I thought this would bypass the oAuth request but it seems that is not so, what is it I'm doing wrong?

Just some further information... for the end result, I basically want to display the last tweet that I made on my site. However I obviously don't want to authenticate via twitter each time.

I may be missing the point of this whole oAuth thing here... do I need to store an oAuth token in my app so that it authenticates automatically without me clicking the YES log in button on the Twitter site.


Twitter none oAuth request with Haughin library - El Forum - 02-23-2011

[eluser]SteRiley[/eluser]
Ok I think I might have my head around this one now...

I made a request to my app on twitter.com, I used the following to return my oAuth tokens:
Code:
$tokens = $this->tweet->get_tokens();
var_dump($tokens);

I've now saved these tokens into my app, which I hope will now do the trick, the final code should look like this.
Code:
$tokens = array( 'oauth_token' => 'MY_OAUTH_TOKEN', 'oauth_token_secret' => 'MY_SECRET_TOKEN' );
$this->tweet->set_tokens($tokens);

$user = $this->tweet->call('get', 'statuses/user_timeline', array('screen_name' => 'SteRiley', 'count' => 1));
var_dump($user);

Can anyone confirm I've gone about this the right way?


Twitter none oAuth request with Haughin library - El Forum - 03-01-2011

[eluser]w0bbes[/eluser]
Im trying to do exactly the same... Let me know if you get it to work. Thanks


Twitter none oAuth request with Haughin library - El Forum - 03-01-2011

[eluser]SteRiley[/eluser]
If you read the second post I explain how its done. You just need to store the oauth_token and oauth_token_secret into your app, I think thats it then.


Twitter none oAuth request with Haughin library - El Forum - 03-01-2011

[eluser]w0bbes[/eluser]
I get bool(false) when I var dump $user....


Twitter none oAuth request with Haughin library - El Forum - 03-03-2011

[eluser]SteRiley[/eluser]
How about when you do the following:

Code:
$tokens = $this->tweet->get_tokens();
var_dump($tokens);

Are you getting your tokens? This is what you'll need to embed into your application.


Twitter none oAuth request with Haughin library - El Forum - 03-03-2011

[eluser]w0bbes[/eluser]
Thanks for your reply.

Yes, im getting my tokens when I var dump it, yet I still get
<code>bool(false)</code>
when I var dump the call


Twitter none oAuth request with Haughin library - El Forum - 03-03-2011

[eluser]SteRiley[/eluser]
Can you post the section of the code your having the problems with?

I've used the following replacing MY_OAUTH_TOKEN & MY_SECRET_TOKEN with the ones dumped from gettokens:

Code:
$tokens = array( 'oauth_token' => 'MY_OAUTH_TOKEN', 'oauth_token_secret' => 'MY_SECRET_TOKEN' );
$this->tweet->set_tokens($tokens);

$user = $this->tweet->call('get', 'statuses/user_timeline', array('screen_name' => 'SteRiley', 'count' => 1));
var_dump($user);



Twitter none oAuth request with Haughin library - El Forum - 03-15-2011

[eluser]w0bbes[/eluser]
**Sorry to bring this up again**

I still havent fixed this,

Here is how my controller looks
Code:
$this->load->library('tweet');
            
            $tokens = array( 'oauth_token' => 'MY_TOKEN', 'oauth_token_secret' => 'MY_KEY' );
            $this->tweet->set_tokens($tokens);
            $took = $this->tweet->get_tokens();
            var_dump($took);
            
            
            $user = $this->tweet->call('get', 'statuses/user_timeline', array('screen_name' => 'briljantmartijn', 'count' => 1));
            var_dump($user);


This will give me the following:
Code:
array(2) { ["oauth_token"]=> string(22) "MY_TOKEN" ["oauth_token_secret"]=> string(42) "MY_KEY" }
bool(false)


Thanks in advance for any help you can give me


Twitter none oAuth request with Haughin library - El Forum - 03-15-2011

[eluser]w0bbes[/eluser]
PS.. when i run the tweet_test.php controller from Elliot's library, it outputs "hi there"

When i try to make a call for the timeline in this test controller i get an exception:
Quote:exception 'tweetException' with message '401 | Request Failed: /statuses/user_timeline.json?screen_name=briljantmartijn&count=1 - Invalid / expired Token' in /home/briljantm0/domains/briljantmedia.nl/public_html/system/application/libraries/tweet.php:205
Stack trace:
#0 /home/briljantm0/domains/briljantmedia.nl/public_html/system/application/libraries/tweet.php(172): tweetConnection->_getResponse('Resource id #35')
#1 /home/briljantm0/domains/briljantmedia.nl/public_html/system/application/libraries/tweet.php(110): tweetConnection->_addCurl('http://api.twit...', Array)
#2 /home/briljantm0/domains/briljantmedia.nl/public_html/system/application/libraries/tweet.php(502): tweetConnection->get('http://api.twit...', Array)
#3 /home/briljantm0/domains/briljantmedia.nl/public_html/system/application/libraries/tweet.php(332): tweetOauth->_httpRequest('GET', 'http://api.twit...', Array)
#4 /home/briljantm0/domains/briljantmedia.nl/public_html/system/application/libraries/tweet.php(19): tweetOauth->call('get', 'statuses/user_t...', Array)
#5 /home/briljantm0/domains/briljantmedia.nl/public_html/system/application/controllers/tweet_test.php(48): tweet->__call(Array, Array)
#6 /home/briljantm0/domains/briljantmedia.nl/public_html/system/application/controllers/tweet_test.php(48): tweet->call('call', Array)
#7 /home/briljantm0/domains/briljantmedia.nl/public_html/system/codeigniter/CodeIgniter.php(236): Tweet_test->index('get', 'statuses/user_t...', Array)
#8 /home/briljantm0/domains/briljantmedia.nl/public_html/index.php(115): require_once('/home/briljantm...')
#9 {main}