Twitter 401:身份验证凭据无效-令牌无效或过期。代码-89

Twitter 401:身份验证凭据无效-令牌无效或过期。代码-89,twitter,twitter4j,Twitter,Twitter4j,这是代码,我收到了错误401:身份验证错误 public class Server { // initialize socket and input stream private Socket socket = null; private ServerSocket server = null; private DataInputStream in = null; public void tweet() throws

这是代码,我收到了错误401:身份验证错误

public class Server { // initialize socket and input stream private Socket socket = null; private ServerSocket server = null; private DataInputStream in = null; public void tweet() throws TwitterException { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDaemonEnabled(true).setOAuthConsumerKey("......") .setOAuthConsumerSecret("......") .setOAuthAccessToken("......") .setOAuthAccessTokenSecret("....."); TwitterFactory tf = new TwitterFactory(); twitter4j.Twitter twitter = tf.getInstance(); List status = twitter.getHomeTimeline(); for (Status st : status) { System.out.println(st.getUser().getName() + "---- Tweets----" + st.getText()); } } // constructor with port public Server(int port) throws TwitterException { // starts server and waits for a connection try { server = new ServerSocket(port); System.out.println("Server started"); System.out.println("Waiting for a client ..."); socket = server.accept(); System.out.println("Client accepted"); // takes input from the client socket in = new DataInputStream(new BufferedInputStream(socket.getInputStream())); String line = ""; // reads message from client until "Over" is sent while (!line.equals("Over")) { try { line = in.readUTF(); System.out.println(line); if (line.equalsIgnoreCase("Data")) { tweet(); } } catch (IOException i) { System.out.println(i); } } System.out.println("Closing connection"); // close connection socket.close(); in.close(); } catch (IOException i) { System.out.println(i); } } public static void main(String args[]) throws TwitterException { Server server = new Server(5000); } } 公共类服务器{ //初始化套接字和输入流 私有套接字=空; 私有服务器套接字服务器=null; 私有DataInputStream in=null; public void tweet()引发TwitterException{ ConfigurationBuilder cb=新的ConfigurationBuilder(); cb.setDaemonEnabled(true).setOAuthConsumerKey(“…”) .SetOAuthConsumerCret(“……”) .setOAuthAccessToken(“……”) .setOAuthAccessTokenSecret(“…”); TwitterFactory tf=新TwitterFactory(); twitter4j.Twitter=tf.getInstance(); 列表状态=twitter.getHomeTimeline(); 对于(状态st:状态){ System.out.println(st.getUser().getName()+“----Tweets-->+st.getText()); } } //带端口的构造函数 公共服务器(int端口)引发TwitterException{ //启动服务器并等待连接 试一试{ 服务器=新的服务器套接字(端口); System.out.println(“服务器已启动”); System.out.println(“等待客户…”); socket=server.accept(); System.out.println(“客户接受”); //从客户端套接字获取输入 in=新的DataInputStream(新的BufferedInputStream(socket.getInputStream()); 字符串行=”; //从客户端读取消息,直到发送“结束” 而(!line.equals(“Over”)){ 试一试{ line=in.readUTF(); 系统输出打印项次(行); if(行等信号(“数据”)){ tweet(); } }捕获(IOI异常){ 系统输出打印LN(i); } } System.out.println(“闭合连接”); //密切联系 socket.close(); in.close(); }捕获(IOI异常){ 系统输出打印LN(i); } } 公共静态void main(字符串args[])引发TwitterException{ 服务器=新服务器(5000); } }
请确保代币有效

然后,您可以尝试启用系统代理,如下所示:


System.setProperty(“java.net.useSystemProxies”,“true”)

这很不幸。遗憾的是,你的问题不是关于nor(即使你可能正在使用这些东西),所以我已经为你删除了这些标签。