资源简介
用来展示twitter数据采集,当初的事例.
代码片段和文件信息
package com.twiter.info.auth;
import java.awt.Desktop;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Properties;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.auth.AccessToken;
import twitter4j.auth.RequestToken;
/**
* @ClassName: GetAccessToken
* @Description:获取授权信息
* @author God
* @date 2014-12-12 上午11:19:53
*
*/
public class GetAccessToken {
public static void main(String[] args) {
String cPath=“D:\\A_WorkSpace\\workspace14_CareerPredict\\twitter\\src\\twitter4j.properties“;
File file = new File(cPath);
Properties prop = new Properties();
InputStream is = null;
OutputStream os = null;
try {
if (file.exists()) {
is = new FileInputStream(file);
prop.load(is);
}
if (args.length < 2) {
if (null == prop.getProperty(“oauth.consumerKey“)
&& null == prop.getProperty(“oauth.consumerSecret“)) {
// consumer key/secret are not set in twitter4j.properties
System.out.println(
“Usage: java twitter4j.examples.oauth.GetAccessToken [consumer key] [consumer secret]“);
System.exit(-1);
}
} else {
prop.setProperty(“oauth.consumerKey“ args[0]);
prop.setProperty(“oauth.consumerSecret“ args[1]);
os = new FileOutputStream(“twitter4j.properties“);
prop.store(os “twitter4j.properties“);
}
} catch (IOException ioe) {
ioe.printStackTrace();
System.exit(-1);
} finally {
if (is != null) {
try {
is.close();
} catch (IOException ignore) {
}
}
if (os != null) {
try {
os.close();
} catch (IOException ignore) {
}
}
}
try {
Twitter twitter = new TwitterFactory().getInstance();
RequestToken requestToken = twitter.getOAuthRequestToken();
System.out.println(“Got access token.“);
System.out.println(“Request token: “ + requestToken.getToken());
System.out.println(“Request token secret: “ + requestToken.getTokenSecret());
AccessToken accessToken = null;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while (null == accessToken) {
System.out.println(“Open the
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
I.A.... 1200 2014-12-15 18:58 twitter\.classpath
I.A.... 383 2014-12-12 10:09 twitter\.project
I.A.... 170 2014-12-13 13:32 twitter\.settings\com.genuitec.eclipse.core.prefs
I.A.... 598 2014-12-12 10:09 twitter\.settings\org.eclipse.jdt.core.prefs
I.A.... 406 2014-12-15 22:57 twitter\bin\beans.xm
I.A.... 5362 2014-12-15 18:58 twitter\bin\com\twiter\info\auth\GetAccessToken.class
I.A.... 1109 2014-12-15 18:58 twitter\bin\com\twiter\info\domain\TwitterInfo.class
I.A.... 242 2014-12-15 18:58 twitter\bin\com\twiter\info\filter\Filter.class
I.A.... 907 2014-12-15 18:58 twitter\bin\com\twiter\info\filter\impl\ContentFilterImpl.class
I.A.... 557 2014-12-15 18:58 twitter\bin\com\twiter\info\rules\Config.class
I.A.... 1306 2014-12-15 18:58 twitter\bin\com\twiter\info\search\impl\InfoParserTest.class
I.A.... 1117 2014-12-15 18:58 twitter\bin\com\twiter\info\search\impl\KeyUtilTest.class
I.A.... 4864 2014-12-15 18:58 twitter\bin\com\twiter\info\search\impl\SearchImpl2.class
I.A.... 4487 2014-12-15 18:58 twitter\bin\com\twiter\info\search\impl\SearchOnGetImpl.class
I.A.... 4504 2014-12-15 18:58 twitter\bin\com\twiter\info\search\impl\SearchOnStreamImpl$1.class
I.A.... 4225 2014-12-15 18:58 twitter\bin\com\twiter\info\search\impl\SearchOnStreamImpl.class
I.A.... 735 2014-12-15 18:58 twitter\bin\com\twiter\info\search\Search.class
I.A.... 1557 2014-12-15 18:58 twitter\bin\com\twiter\info\service\impl\TwiterServiceImpl.class
I.A.... 1021 2014-12-15 18:58 twitter\bin\com\twiter\info\service\impl\TwiterServiceImpl2$1.class
I.A.... 2370 2014-12-15 18:58 twitter\bin\com\twiter\info\service\impl\TwiterServiceImpl2.class
I.A.... 199 2014-12-15 18:58 twitter\bin\com\twiter\info\service\SearchService.class
I.A.... 4707 2014-12-15 18:58 twitter\bin\com\twiter\info\utils\DateUtil.class
I.A.... 2637 2014-12-15 18:58 twitter\bin\com\twiter\info\utils\FileUtil.class
I.A.... 1279 2014-12-15 18:58 twitter\bin\com\twiter\info\utils\KeyUtil.class
I.A.... 1156 2014-12-15 18:58 twitter\bin\com\twiter\info\utils\ParserUtil.class
I.A.... 281 2014-12-15 19:12 twitter\bin\Log4j.properties
I.A.... 2381 2014-12-15 18:58 twitter\bin\twitter4j\examples\stream\PrintFilterStream$1.class
I.A.... 2923 2014-12-15 18:58 twitter\bin\twitter4j\examples\stream\PrintFilterStream.class
I.A.... 978 2014-12-15 18:58 twitter\bin\twitter4j\examples\stream\PrintRawSampleStream$1.class
I.A.... 954 2014-12-15 18:58 twitter\bin\twitter4j\examples\stream\PrintRawSampleStream.class
............此处省略77个文件信息
- 上一篇:课程设计电子密码锁报告
- 下一篇:华科操作系统课程设计报告
评论
共有 条评论