开发者

PHP Twitter Oauth for just retrieving feeds

开发者 https://www.devze.com 2023-01-14 20:38 出处:网络
So I\'ve been using Twitter PHP LIB for pullin开发者_JS百科g user tweets & followers tweets. OpenAuth seems like overkill for this as I need to get the site itself to register for authentication.

So I've been using Twitter PHP LIB for pullin开发者_JS百科g user tweets & followers tweets. OpenAuth seems like overkill for this as I need to get the site itself to register for authentication.

Is there a simple library that I can use? Perhaps a basic Oath if you don't need authentication by the user at all?

Should I simply pull the RSS?=


I made my own Twitter OAuth library. It still uses OAuth but the library is very small.

Also, you still need to register an app for it and get the access token.

If you want to check it out, here is it: I Just Want to Call Twitter’s API With My Own Account!

Basically you need the consumer key, the consumer secret, the access token and the access token secret, so you have to register your application at [dev.twitter.com] (http://dev.twitter.com/) using the user you want to authenticate, then you will get the first 2. On the same page, click on "My Access Token" and you will get the last 2.

Then you can:

$api = new OAuthDamnit(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
echo $api->get('http://api.twitter.com/1/statuses/home_timeline.json', array()); 

There are other alternatives such as using PHP's OAuth Extension which I think might be faster, but is is also very simple to use.

$oauth = new OAuth(CONSUMER_KEY, CONSUMER_SECRET, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_AUTHORIZATION);
$oauth->setToken(ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
$oauth->fetch('http://api.twitter.com/1/statuses/home_timeline.json');
echo $oauth->getLastResponse();

Or if you don't want to use OAuth at all, you have Simple Auth Twitter which can act like a basic auth gateway.

You just have to sign it there and it will give you an API key. You use that as your Twitter password and use http://simpleauthtwitter.heroku.com/api/ as the API endpoint.

0

精彩评论

暂无评论...
验证码 换一张
取 消