使用 twitter4j 库拥有多个 Twitter 实例. [英] Having multiple Twitter instances with twitter4j library.

查看:34
本文介绍了使用 twitter4j 库拥有多个 Twitter 实例.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要能够使用相同的消费者密钥和秘密但不同的用户级别访问令牌制作不同的 Twitter 实例.

I need to be able to make different Twitter instances with same consumer key and secret but different user level access tokens.

我已经使用标准 Twitter OAuth 登录协议根据我的应用程序的消费者凭据获取了 10 个用户的访问令牌.现在,我想创建一个 Twitter 实例列表,每个实例都使用单独的 Accesstoken 进行初始化.但是,我无法做到这一点.

I have already obtained the access tokens for 10 users based on consumer credentials of my app by using standard Twitter OAuth Sign In protocol. Now, I want to create a list of Twitter Instances each initialized with a separate Accesstoken. However, I'm not able to do this.

我感到困惑的主要原因是,我不明白 Twitter4j 如何实例化 Twitter 实例.我不明白 TwitterFactory.getSingleton() 方法和 TwitterFactory().getInstance() 方法之间的区别.

My leading cause of confusion is, that, I don't understand how Twitter4j instantiates Twitter instances. I don't understand the difference between TwitterFactory.getSingleton() method and TwitterFactory().getInstance() method.

我也不明白 AccessTokens 是否可以在不提供消费者密钥和秘密的情况下独立工作.或者我是否需要在使用 Accesstokens 时提供消费者密钥和秘密.

I also don't understand if AccessTokens can work independently without supplying consumer key and secret. Or do I need to provide Consumer key and secret while using Accesstokens.

如果有人可以详细解释我的要求的设计,我将不胜感激.

If someone can explain in detail the design for my requirement it'll be highly appreciated.

推荐答案

简而言之,您可能需要这样的代码:

In short, you may want code like this:

TwitterFactory tf = new TwitterFactory();
Twitter user1 = tf.getInstance(new AccessToken("XXX","XXX"));
Twitter user2 = tf.getInstance(new AccessToken("XXX","XXX"));

一个 Twitter 实例只能处理一个帐户.处理多个账号,需要用 TwitterFactory#getInstance(AccessToken); 实例化多个 Twitter 实例;

A Twitter instance can handle only one account. To deal with multiple accounts, you need to instantiate multiple Twitter instances with TwitterFactory#getInstance(AccessToken);

不建议硬编码消费者密钥/秘密,您可能希望在 twitter4j.properties 中指定它们.http://twitter4j.org/en/configuration.html#fileconfiguration

Hard-coding consumer key/secret is not suggested and you may want to specify them in twitter4j.properties. http://twitter4j.org/en/configuration.html#fileconfiguration

这篇关于使用 twitter4j 库拥有多个 Twitter 实例.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆