-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from shortintern2020-A-labyrinth/feature/conne…
…ction_twitterAPI_NLPAPI Feature/connection twitter api nlpapi
- Loading branch information
Showing
9 changed files
with
124 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/com/example/demo/controller/TwitterController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.example.demo.controller; | ||
|
||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import twitter4j.*; | ||
|
||
import java.io.IOException; | ||
|
||
@RestController | ||
@RequestMapping(path = "/twitter") | ||
public class TwitterController { | ||
|
||
@GetMapping("/search_keyword") | ||
public QueryResult search_keyowrd(@RequestParam(name = "searchword", defaultValue = "チンチン") String searchword) throws TwitterException { | ||
// 初期化 | ||
Twitter twitter = new TwitterFactory().getInstance(); | ||
Query query = new Query(searchword); | ||
|
||
QueryResult result = twitter.search(query); | ||
|
||
// for debug. show tweet results on CLI | ||
for (Status status : result.getTweets()) { | ||
System.out.println("@" + status.getUser().getScreenName() + ":" + status.getText()); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
@RequestMapping(path = "/search_user", method = RequestMethod.GET) | ||
public QueryResult search_user(@RequestParam(name = "username", defaultValue = "CNN") String username, | ||
@RequestParam(name = "tweet_id", defaultValue = "1000000") long tweet_id | ||
) throws TwitterException { | ||
// 初期化 | ||
Twitter twitter = new TwitterFactory().getInstance(); | ||
Query query = new Query(); | ||
|
||
//ユーザーネームで指定.sinceId以降のtweetから15個取ってくる.最新のツイートから時系列順に取ってくるっぽい。 | ||
query.setQuery("from:" + username); | ||
query.setSinceId(tweet_id); | ||
|
||
QueryResult result = twitter.search(query); | ||
|
||
//for debug on CLI. | ||
for (Status status : result.getTweets()) { | ||
System.out.println("@" + status.getUser().getScreenName() + ":" + status.getText()); | ||
} | ||
|
||
//TODO: ここで取ってきたLatestTweetIdを保存しておいて、次回からそのidのツイート以降のツイートを拾ってくればOK | ||
|
||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file modified
BIN
+3.58 KB
(180%)
target/classes/com/example/demo/controller/ViewController.class
Binary file not shown.
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
target/classes/com/example/demo/repository/ViewRepository.class
Binary file not shown.
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
target/test-classes/com/example/demo/DemoApplicationTests.class
Binary file not shown.