MintState Forums
뒤로 MintState BBS > Tech > Ajax & Issue
멤버이름    오토

PHP Twitter Search API

페이지 정보

작성자 MintState 댓글 0건 조회 11,080회 작성일 11-06-01 15:34


PHP Twitter Search API

I've implemented the twitter search API in a PHP class just for fun. It implements the entire search API as of February 25, 2009. I've only tested this with PHP 5.2.6 but I am fairly confident that most installations of PHP5 should work just fine. If you try it with PHP4 and it works (or if you have to jigger it) let me know.

You can get the source code at

Here are a couple examples (after including the class):

This example makes use of method chaining to create a "sentence". Chaining isn't a requirement but I think it works here. What this example does is search for tweets from the user "ryanfaerman" with the hashtag "#flsccc".

$search = new TwitterSearch();
$search->user_agent = '';

$results = $search->from('ryanfaerman')->with('flsccc')->results();
The user agent is optional, but is recommended. This way the folks over at Twitter know who is hitting their server. I'll be leaving it out in other examples for clarity.

If you want to put in the query during instantiation, you can do that too. Anything that you'd use on can be passed as the argument. This example searches all twitter for any tweets that mention the word "monkey".

$search = new TwitterSearch('monkey');
$results = $search->results();
Each time you add another search term, it is appended to the query you are building. Once you get the results, the query is cleared.

This example searches for the last 50 tweets from the user ?darthvader? where he mentions ?storm trooper?.

$search->contains('storm trooper');
$results = $search->rpp(50)->results();
This example searches for any tweets within a 25 mile radius of the provided coordinates.

$results = $search->geocode(40.757929, -73.985506, 25)->results();
There are quite a few more search operators which are clear from the source code, so I encourage you to take a look. Lastly, there is the trends function. Calling this method returns the top ten queries that are currently trending on Twitter.

$trends = $search->trends();
If you end up using this in a project of yours, I'd really enjoy hearing about it.

첨부 파일
파일 종류: php TwitterSearch.php (10.2K, 62 views)


등록된 댓글이 없습니다.

Total 32건 1 페이지
Ajax & Issue 목록
번호 제목 글쓴이 조회 날짜
32 MintState 8055 02-02
31 MintState 8854 05-30
30 MintState 10514 03-04
29 MintState 11779 03-21
28 MintState 11595 11-25
27 MintState 16141 09-19
26 MintState 12901 06-23
25 MintState 10343 06-01
24 MintState 14922 06-01
열람중 MintState 11081 06-01
22 MintState 12685 04-18
21 MintState 11278 02-21
20 MintState 14662 07-13
19 MintState 14933 07-02
18 MintState 12120 01-19
17 MintState 16846 01-19
16 MintState 15269 08-27
15 MintState 14721 08-27
14 MintState 15180 07-07
Google Maps API 댓글+ 1
MintState 20526 03-18
게시물 검색
모바일 버전으로 보기
CopyRight ©2004 - 2023, MintState. ™