我已经浏览了大量的博客和教程,使用Twitter 4j库编写一个简单的推文程序,但很少有用.有人可以为我提供一个网站,其中包含有关相同步骤的良好教程.
我正在使用Twitter4j开发应用程序.我正在尝试使用某个标签导入推文(例如:天气)然后,我想通过搜索关键字对推文进行分类.
例如:导入的一些推文可能是
- OMG, I hate this rain #weather
- This sunshine makes me feel so happy #weather
- Such strange #weather! One moment it rains, the next the sun shines. Confusing!
- Rain makes me sad #weather
- I love the sunshine! #weather
Run Code Online (Sandbox Code Playgroud)
然后,我想将这些推文归类为:
- hate, Confusing, sad,... are negative
- happy, love,... are positive
Run Code Online (Sandbox Code Playgroud)
PositiveTweets将是:
- This sunshine makes me feel so happy #weather
- I love the sunshine! #weather
Run Code Online (Sandbox Code Playgroud)
NegativeTweets将是:
- OMG, I hate this rain #weather …Run Code Online (Sandbox Code Playgroud) 我正在尝试将Twitter集成到我的Android应用程序中,似乎无法让Twitter4j注册我的应用程序.
关于我在Android上看到过的问题的每个教程和问题都已经存在了很多年,从那以后事情似乎已经发生了变化.
我按照本教程中的步骤操作,并使用提供的源代码测试连接到Twitter.知道随源代码提供的Twitter4j版本已经过时了,我后来更新了最新版本和快照版本,但都无济于事.
private void loginNewUser() {
try {
Log.i(TAG, "Request App Authentication");
// This line fails with error "Host is unresolved: api.twitter.com:80
mReqToken = mTwitter.getOAuthRequestToken();
Log.i(TAG, "Starting Webview to login to twitter");
WebView twitterSite = new WebView(this);
twitterSite.loadUrl(mReqToken.getAuthenticationURL());
setContentView(twitterSite);
} catch (TwitterException e) {
Log.e("errors", e.getMessage());
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
}
}
Run Code Online (Sandbox Code Playgroud)
任何人都有使用Twitter4j的任何工作登录代码或知道问题的解决方案我将不胜感激收到你的消息!
我正在努力弄清楚发生了什么.我有一个典型的应用程序结构,它产生一个负责获取Twitter令牌的OAuthActivity,然后我的主应用程序活动将该令牌用于各种与twitter相关的操作.
我的OAuthActivity有效.我得到一个身份验证令牌,Twitter网页正确显示我的应用程序名称等....此外,在该活动中,我可以发送推文并发布..这意味着OAuthActivity工作,时钟同步,令牌有效等等......
但是当这个OAuthActivity完成并返回到调用活动时,每当我尝试使用该标记(从持久化的密钥/秘密重新创建它)时,无论什么操作,操作总是会失败,并抱怨说AuthChallenge报告为null.就像我提供了一个空令牌,但我还没有!
请查看附件我的OAuthActivity的来源,以及我如何在主要活动中初始化Twitter对象的来源.如果你看错了,请告诉我.
PD - 我显然已经检查过我分配的令牌值与我得到的相同!还尝试了不同的方式来实例化Twitter,通过属性,通过构建器,通过集....并没有任何变化:(
编辑 - >我发现我必须在新的Twitter对象上调用" verifyCredentials() ",如果我想重用一个令牌,但是......没有运气!(请在最后找到发布的例外)
EDIT-2>如果我同时使用子活动和父项
mTwitter=TwitterFactory.getSingleton()
Run Code Online (Sandbox Code Playgroud)
然后twitter对象起作用,但这对我来说并不是真的可以接受,因为它不使用持久性,我需要每次都授权应用程序.此外,只有Twitter对象被授权,TwitterStream不断抛出异常.
干杯!
父活动的源代码,我尝试使用在子活动中获得的访问令牌,如下所示.无论我尝试使用此令牌,总是获得401.
private void init_twitter(String tok, String sec) {
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey(Conf.OAUTH_CONSUMER_KEY)
.setOAuthConsumerSecret(Conf.OAUTH_CONSUMER_SECRET)
.setOAuthAccessToken(tok)
.setOAuthAccessTokenSecret(sec);
TwitterFactory tf = new TwitterFactory(cb.build());
mTwitter=tf.getInstance();
/** This always fails, even though I call this routine with the
correct token & secret !!! See at the enf of message for an …Run Code Online (Sandbox Code Playgroud) 我想将我的项目与Twitter集成.所以,我正在使用twitter4j.我正在使用gradle来管理依赖项.
目前,我正面临这个问题:
java.lang.NoClassDefFoundError: twitter4j.conf.ConfigurationBuilder
Run Code Online (Sandbox Code Playgroud)
我用Google搜索并找到了一个解决方案,即将"lib"文件夹的名称更改为"libs",但这适用于Eclipse.如何在Android Studio中解决此问题?
谢谢!
如何向搜索方法添加多个查询?我会在servlet中使用它.
这是我现在的代码:
private static void searchQuery(Twitter twitter) {
try {
Query query = new Query("test soccer");
QueryResult result;
do {
result = twitter.search(query);
List<Status> tweets = result.getTweets();
System.out.println("tweets: " + tweets.size());
for (Status tweet : tweets) {
System.out.println("@" + tweet.getUser().getScreenName() + " - " + tweet.getText());
}
} while ((query = result.nextQuery()) != null);
System.exit(0);
} catch (TwitterException te) {
te.printStackTrace();
System.out.println("Failed to search tweets: " + te.getMessage());
System.exit(-1);
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助!
我已经成功设置了twitter4j,现在可以发布文本更新,并将本地媒体从设备上传到twitter.但我真正需要做的是从网络共享远程图像 - 例如,http://example.com/image.png.
当我执行此代码时......
StatusUpdate statusUpdate = new StatusUpdate("Hello Twitter");
String imageUrl = "http://example.com/image.png";
File file = new File(imageUrl);
statusUpdate.setMedia(file);
twitter4j.Status status = twitter.updateStatus(statusUpdate);
...看起来twitter4j试图将url视为本地,因为它似乎放在/它前面,然后抛出异常说...
/http://example.com/image.png: open failed: ENOENT (No such file or directory)
怎么解决?谢谢.
我试图在twitter4j上使用proguard并在调用时不断收到noMethodFound异常new TwitterFactory(configuration).这是例外:
java.lang.AssertionError: java.lang.NoSuchMethodException: <init> [interface twitter4j.conf.Configuration, interface twitter4j.auth.Authorization]
at twitter4j.TwitterFactory.<clinit>(TwitterFactory.java:73)
at com.applicaster.util.twitter.TwitterAuthenticationUtil.getServiceInstance(Unknown Source)
at com.applicaster.util.twitter.TwitterAuthenticationUtil.logIn(Unknown Source)
at feed.x.b(Unknown Source)
at feed.A.onClick(Unknown Source)
at android.view.View.performClick(View.java:4442)
at android.view.View$PerformClick.run(View.java:18473)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5105)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NoSuchMethodException: <init> [interface twitter4j.conf.Configuration, interface twitter4j.auth.Authorization]
at java.lang.Class.getConstructorOrMethod(Class.java:472)
at java.lang.Class.getDeclaredConstructor(Class.java:562)
at twitter4j.TwitterFactory.<clinit>(TwitterFactory.java:71)
at com.applicaster.util.twitter.TwitterAuthenticationUtil.getServiceInstance(Unknown Source)
at com.applicaster.util.twitter.TwitterAuthenticationUtil.logIn(Unknown Source)
at feed.x.b(Unknown Source)
at feed.A.onClick(Unknown Source)
at android.view.View.performClick(View.java:4442)
at android.view.View$PerformClick.run(View.java:18473)
at …Run Code Online (Sandbox Code Playgroud) 我正在使用Twitter4j访问流API。我正在使用follow,以获取与一组用户相关的流。我的问题基本上可以归结为:给定流中的一个转发(我有转发的ID和用户的ID),如何找到:
我不认为API公开了这个吗?
任何人都知道是否可以从twitter api获取所有网址照片.作为一个例子,这条推文有4张照片https://twitter.com/wtfbaile/status/652694439584993280/photo/1 我想在twitter api上的一个请求中获取所有4个url照片.
目前为了做到这一点,我必须做2个请求.4个网址照片仅在第二个请求中提供.
第一个 :
结果:
{
"statuses": [
{
"metadata": {
"result_type": "recent",
"iso_language_code": "en"
},
"in_reply_to_status_id_str": null,
"in_reply_to_status_id": null,
"created_at": "Sat Oct 10 03:57:35 +0000 2015",
"in_reply_to_user_id_str": null,
"source": "<a href=\"http:\/\/twitter.com\/download\/iphone\" rel=\"nofollow\">Twitter for iPhone<\/a>",
"retweet_count": 1,
"retweeted": false,
"geo": null,
"in_reply_to_screen_name": null,
"is_quote_status": false,
"id_str": "652694439584993280",
"in_reply_to_user_id": null,
"favorite_count": 6,
"id": 6.5269443958499e+17,
"text": "some cool pictures from time square, brooklyn bridge and china town http:\/\/t.co\/kv0OVmoMoI",
"place": null,
"lang": "en",
"favorited": false,
"possibly_sensitive": false,
"coordinates": …Run Code Online (Sandbox Code Playgroud)