简体   繁体   中英

twitter4j.TwitterException: 401:Authentication credentials were missing or incorrect

I am developing web based application in Java [GWT]
I am facing problem with TwitterException.
I used valid credential.
Twitter twitter = new Twitter(myTwitterId, myTwiterPwd);
when I call twitter.getFollowers() method

I got following Error Message

twitter4j.TwitterException: 401:Authentication credentials were missing or incorrect.

<?xml version="1.0" encoding="UTF-8"?>
<errors>
    <error code="53">Basic authentication is not supported</error>
</errors>

    at twitter4j.http.HttpClient.httpRequest(HttpClient.java:469)
    at twitter4j.http.HttpClient.get(HttpClient.java:412)
    at twitter4j.Twitter.get(Twitter.java:276)
    at twitter4j.Twitter.get(Twitter.java:228)
    at twitter4j.Twitter.getFollowersStatuses(Twitter.java:1363)
    at twitter4j.Twitter.getFollowers(Twitter.java:1350)
    at com.vaibhav.dealelephant.server.impl.TwitterServiceImpl.getTwitterFollowers(TwitterServiceImpl.java:49)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:562)
    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:188)
    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:224)
    at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Thread.java:619)

I want to display My followers Images into My Website, but it throws exception after calling this method method. 方法后会抛出异常。 SO unable to get My follwers Images :(

Please provide me Easy solution for the same

Hope for the best co-operation from your side

Thanks in advance !!!

Yes, your authentication is not working because Twitter made some recent changes regarding how it lets 3rd party code authenticate.

In other words, Basic authentication has been turned off for the API.

As Allain mentions, oAuth is the way to go.

The code you posted is different than what I've seen in the past for connecting. I think (though I'm not sure) that oAuth is the preferred way of authenticating now.

Here's a blog that details using oAuth to connect.

我遇到了麻烦,最后解决方案是在我的Twitter API( https://dev.twitter.com/ )上放置一个有效的回拨网址,我使用谷歌+网址,保存更改(可能需要几分钟才能到达进行更改,刷新页面以确保)并且工作正常。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM