我在Scala项目中使用Java Twitter4J库.
我正在调用这个方法
twitter.getFriendsStatuses()
Run Code Online (Sandbox Code Playgroud)
此方法返回包含状态的twitter4j.User对象列表.
我尝试迭代它们,它在第一个元素上进行无限循环:
val users:List[User] = twitter.getFriendsStatuses(userId, paging.getSinceId())
while( users.iterator.hasNext() ) {
println(users.iterator.next().getStatus())
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
正如标题所说,我正在使用Twitter4J API,我似乎无法找到如何计算"Tweet"实例的转发.
我正在使用twitter4j并开发StatusListener类,需要一种方法来创建一个模拟Status对象,以便我可以测试我的类.在开发过程中,我不想实际连接到API.
有没有办法从json字符串创建一个Status对象?我只想从Twitter下载一个状态,将其保存为字符串,然后在我开发时重复使用它来创建Status对象.
谁能告诉我怎么做?
我试过的:
我已经在twitter上注册了一个应用程序并获得了Consumer Key和Secret.Even我有各种代码可以通过twitter登录.这些是我试过的:
http://thetechnib.blogspot.com/2011/01/android-sign-in-with-twitter.html
[此链接已死,您可以在此处查看存档]
http://www.android10.org/index.php/articleslibraries/291-twitter-integration-in-your-android-application
我遇到的问题:
直到现在,上面的代码带我到twitter登录,让我登录并有一个PIN来完成登录过程.但我不知道如何使用它来让我的应用程序工作.我检查了整个代码,但没有发现任何相关的销.
其次,当我在Twitter上注册我的应用程序时,它要求回拨URL但是因为它写的是它真的不需要,我跳过指定.(即使我不知道应该是什么!)
因此,我在我的应用程序中将null作为CallbackURL.
任何人都可以建议我,我如何使用此PIN完成登录过程并让用户回到我的应用程序的主要活动?它是引起问题的回调网址还是我做错了的其他事情?
请回复.任何帮助appriciated!谢谢.
编辑:
正如Frankenstein建议的那样,我在github.com/ddewaele/AndroidTwitterSample/downloads上尝试了代码
我添加了我的消费者密钥和消费者密钥以及回调网址:
public static final String OAUTH_CALLBACK_SCHEME= "x-oauthflow-twitter";
public static final String OAUTH_CALLBACK_HOST= "callback";
public static final String OAUTH_CALLBACK_URL= OAUTH_CALLBACK_SCHEME + "://" + OAUTH_CALLBACK_HOST;
Run Code Online (Sandbox Code Playgroud)
但它给了我这个错误:
logcat的:
11-29 11:56:56.249: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(3081): Error during OAUth retrieve request token
11-29 11:56:56.249: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(3081): oauth.signpost.exception.OAuthNotAuthorizedException: Authorization failed (server replied with a 401). This can happen if the consumer key was not correct or the signatures did not match.
11-29 11:56:56.249: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(3081): …Run Code Online (Sandbox Code Playgroud) logcat的:
12-05 23:37:01.721:W/System.err(534): 401:Authentication credentials (https://dev.twitter.com/docs/auth) were missing or incorrect. Ensure that you have set valid conumer key/secret, access token/secret, and the system clock in in sync.
12-05 23:37:01.721: W/System.err(534): 401:Authentication credentials (https://dev.twitter.com/docs/auth) were missing or incorrect. Ensure that you have set valid conumer key/secret, access token/secret, and the system clock in in sync.
12-05 23:37:01.721: W/System.err(534): error - Read-only application cannot POST
12-05 23:37:01.721: W/System.err(534): request - /1/statuses/update.json
Run Code Online (Sandbox Code Playgroud)
虽然我可以通过(getScreenName()函数)读取屏幕名称并设置读取,写入我的twitter应用程序的权限,但它给出了上面的logcat.And我正在使用twitter4j jar文件.
使用getFriendsId(),我只能检索经过身份验证的当前用户的朋友/关注者列表.我想要的是获得经过身份验证的用户的关注者或朋友的朋友列表.
这是我的第一篇Stackoverflow帖子,对不起,如果不是很好的话.反馈肯定会有所帮助!
我目前正在java.lang.OutOfMemoryError: Java Heap space使用Twitter Streaming API处理项目问题.
在大约500 - 1000条推文中流式传输之后出现错误,我无法确定导致它发生的原因.
在我的onStatus方法中StatusListener我有以下代码:
public void onStatus(Status status) {
tweetCount++;
System.out.println("Tweet #" + tweetCount);
String statusInfo = status.getText().replaceAll("\n", "").replaceAll("\r", "");
String usersCountry = getTweetUserLocation(status);
status = null;
if(!usersCountry.equals("INVALID_LOCATION")){
countryList.updateWhoTalkedAboutWho(usersCountry, statusInfo);
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
System.out.println("Exception in onStatus() catch block");
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
错误可能是由状态进入的速度引起的吗?我可以理解为什么如果状态比处理速度快得多,它会占用更多内存.
另一个嫌疑人是BufferReader,这里是代码:
URL url = new URL(urlStr);
URLConnection conn = url.openConnection();
BufferedReader rd …Run Code Online (Sandbox Code Playgroud) 我试图了解如何在 Java 中正确“扩展”第 3 方库(包括类和接口)以及如何简单地将它们用作替代品。
我目前正在使用Twitter4J图书馆。现在我必须手动添加每次调用方法@的结果:getScreenName()User
twitter4j.User user = getTwitterUser();
String userHandle = "@" + user.getScreenName();
Run Code Online (Sandbox Code Playgroud)
我目前已经尝试了一些东西,但没有任何效果。这是我想出的:
package my.app;
public abstract class User implements twitter4j.User {
public String getHandle() {
return "@" + getScreenName();
}
}
Run Code Online (Sandbox Code Playgroud)
像这样称呼它:
User user = (User) getTwitterUser();
String userHandle = user.getHandle();
Run Code Online (Sandbox Code Playgroud)
这与消息崩溃:
java.lang.ClassCastException: twitter4j.UserJSONImpl cannot be cast to my.app.User
Run Code Online (Sandbox Code Playgroud) 我正在使用 Pythontweepy库。
我使用以下代码成功提取了推文的“喜欢”和“转发”计数:
# Get count of handles who are following you
def get_followers_count(handle):
user = api.get_user(handle)
return user.followers_count
# Get count of handles that you are following
def get_friends_count(handle):
user = api.get_user(handle)
return user.friends_count
# Get count of tweets for a handle
def get_status_count(handle):
user = api.get_user(handle)
return user.statuses_count
# Get count of tweets liked by user
def get_favourite_count(handle):
user = api.get_user(handle)
return user.favourits_count
Run Code Online (Sandbox Code Playgroud)
但是,我找不到获取特定推文的回复计数的方法。
是否可以使用 tweepy 或任何其他库(如 twython 甚至 twitter4j)获取推文的回复计数?
我有一个 twiiter 应用程序:
// 不记名令牌
// API 密钥
// API 密钥秘密
// 访问令牌:
// 访问令牌秘密:
和 Read, Write, and Direct Messages 权限
我使用 ConfigurationBuilder 类在 Java 中以编程方式配置 Twitter4J:
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey("IX9qalH5azhSk61ZoFMiL83Jg") // API key
.setOAuthConsumerSecret("tidoT2GgVZE3B3txDb64tuinlv0wZHbKesX5bNIcjPWpxmcYcs") // API key secret
.setOAuthAccessToken("1345093646195010258-goY3W4oyqSltGFSUNPwJy8pSjSmfI5") // Access token:
.setOAuthAccessTokenSecret("ijkpYB8sacVcBdvKHOnh95Y3QRITzD3c4Uq8nUUMLTN8O"); //Access token secret:
TwitterFactory tf = new TwitterFactory(cb.build());
return tf.getInstance();
Run Code Online (Sandbox Code Playgroud)
但是当我尝试发布时出现此错误:
401:Authentication credentials (https://dev.twitter.com/pages/auth) were missing or incorrect. Ensure that you have set valid consumer key/secret, access token/secret, and the system clock …Run Code Online (Sandbox Code Playgroud) twitter4j ×10
java ×7
twitter ×4
android ×2
api ×1
casting ×1
heap-memory ×1
login ×1
memory-leaks ×1
oauth ×1
python ×1
scala ×1
spring-boot ×1
tweepy ×1
twython ×1