tags:

views:

458

answers:

4

Hi guys,

I am trying to write an php twitter script which will be run by crontab, what the script does is to get the tweets from a dedicated twitter account.

I have looked at some of the php twitter oauth libraries, all of them seem to use redirect to a twitter page to get a token, then goes back to a callback link. In my case I don't want to have any user interaction at all.

Could anyone please tell me what I should do?

Regards

James

A: 

Unless the account is private, you don't need to be authenticated.

Or use OAuth, and authenticate using an admin screen.

We do not currently expire access tokens. You access token will be invalid if a user explicitly rejects your application from their settings or if a Twitter admin suspends your application. If your application is suspended there will be a note on your application page saying that it has been suspended.

http://apiwiki.twitter.com/OAuth-FAQ

Simon Brown
cheers mate, thanks for answering.
James Lin
they currently do not expire tokens, but will be very soon as I read from one of the dev guys on google chat.
James Lin
When it expires, you could set it to send you an email.
Simon Brown
this is the problem, the bot script is for commercial purpose, I cannot baby sit it every hour. http://groups.google.com/group/twitter-development-talk/browse_thread/thread/20fe716ba2d20bff"A request token is expected to be very short lived, since it's only used to exchange for an access token. Right now they do not expire but in an upcoming change we're going to limit them to a one hour life span to improve performance and scalability. The life span of an access token is detailed at http://apiwiki.twitter.com/OAuth-FAQ. Thanks; — Matt Sanford "
James Lin
+1  A: 

You shouldn't need to be using the Twitter API at all. Tweets are public resources, accessible via HTTP.

Here's the official Twitter account's last 10 tweets, available as JSON or XML.

Matchu
what if I want to post tweets using that dedicated account??? The script looks at the tweets and then do some backend processing then post replies...
James Lin
@James Lin: Hrm. I haven't used the Twitter API in enough depth to know whether or not using flat usernames and passwords is still allowable. You might have to do something fancy like authorize your application to act on the dummy user's account without asking, or simply run through Twitter's web interface.
Matchu
@Matchu "You might have to do something fancy like authorize your application to act on the dummy user's account without asking" how do I do that???? cheers!
James Lin
@James Lin: I've never done it; I've only seen it done. Although, now that I think about it, they authorize applications through OAuth, right? So you can just do that OAuth authentication one time to confirm your application, and be able to act on that dummy user's behalf forever after, right? Since I'm on at least one website that does.
Matchu
I was going to do that, but twitter will be expiring the tokens very soon, although I know they don't expire currently...
James Lin
+1  A: 

I use oAuth for my Twitter bot. I got the oAuth token by making a web interface and signing it up. I then pass the token with my calls.

I use Abraham's oAuth library: http://twitteroauth.labs.poseurtech.com/connect.php

You can use the example from the library to get the token. Just have it echo the token from the $_SESSION it creates on the callback.

Jayrox
@Jayrox does your method rely on never expire token or it will work even twitter expires the tokens?
James Lin
to my previous comment, yes your method does not depend on the expiry date. however requires you to expose a callback page on the net...
James Lin
only for the first time. my bot does not have a call back or the oAuth handshake while it runs.
Jayrox
thanks for helping Jayrox
James Lin
no problem :)))) (extra chins for 15 chars)
Jayrox
+2  A: 

Twitter provides a single access token feature on dev.twitter.com designed just for this use.

http://dev.twitter.com/pages/oauth_single_token

abraham
cool this seems the way to go, cheers!
James Lin