Welcome Guest, Not a member yet? Register   Sign In
Twitter none oAuth request with Haughin library
#1

[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.
#2

[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?
#3

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

[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.
#5

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

[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.
#7

[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
#8

[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);
#9

[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
#10

[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}




Theme © iAndrew 2016 - Forum software by © MyBB