问题描述
我想获得Twitter的追随者用户列表为什么我用下面的code,但让空指针在的(用户用户:追随者)
,看到这个链接<一个href="http://grep$c$c.com/file/repo1.maven.org/maven2/org.twitter4j/twitter4j-examples/2.2.4/twitter4j/examples/list/GetAllUserLists.java" rel="nofollow">http://grep$c$c.com/file/repo1.maven.org/maven2/org.twitter4j/twitter4j-examples/2.2.4/twitter4j/examples/list/GetAllUserLists.java在这里,他们引导到如何让用户在Java中,但 ResponseList&LT;在UserList&GT;名单= twitter.getAllUserLists(参数[0]);
在这个环节是什么ARG [0]为每个方法的请指导我解决我的问题。
私有静态最后弦乐用户=您的用户;
私有静态最后弦乐PW =你的密码;
//做一个Twitter的对象
叽叽喳喳叽叽喳喳=新TwitterFactory()的getInstance(用户,PW)。
//设置我的状态
twitter.setStatus(@ vogella与Twitter在Java中搞乱);
清单&lt;使用者&GT;追随者= twitter.getFollowers();
对于(用户用户:追随者){
的System.out.println(user.getName());
}
}
按我的知识,Twiiter已经更新了他们的API,现在他们支持的OAuth 2.0的机制来获取任何信息。
要检索的追随者LIS,你应该使用下面的链接 https://dev.twitter.com/docs/api/1/get /追随者/ IDS 您可以使用Twitter4j库的Java / Android的 http://twitter4j.org/en/index.html
私人无效twitter_req()
{
字符串access_token = prefs.getString(twitter_token,NULL);
字符串access_secret = prefs.getString(twitter_secret,NULL);
twitter_api拉皮=新twitter_api(access_token,access_secret,新GetUserInfo_TWRequestCallback());
lapi.get(api.twitter.com/1/followers/ids.json);
}
公共无效的get(){
尝试 {
HTTPGET HTT prequest =新HTTPGET(mUrl);
符号(HTT prequest);
sendSync(HTT prequest);
}赶上(例外五){
Log.d(获得(),e.toString());
doFailCallback();
}
}
私人无效sendSync(Htt的prequestBase HTT prequest)
{
HttpClient的HttpClient的=新DefaultHttpClient();
HTT presponse HTT presponse = httpClient.execute(HTT prequest);
状态行状态行= HTT presponse.getStatusLine();
HttpEntity实体= HTT presponse.getEntity();
//
//
响应=空;
如果(实体!= NULL){
响应= getResponseFromStream(entity.getContent()); //
}
}
公共无效标志(Htt的prequestBase HTT prequest)抛出OAuthMessageSignerException,OAuthExpectationFailedException {
// MSOAuth的OAuth = MSOAuth.init(mSession);
// oauth.sign(HTT prequest);
尝试 {
consumer.sign(HTT prequest);
}赶上(OAuthCommunicationException E){
响应=errorsign;
如果(E!= NULL)
如果(e.getMessage()!= NULL)
{
响应= e.getMessage();
}
// TODO自动生成的catch块
e.printStackTrace();
}
}
i want to obtain twitter follower user list that why i am using following code but giving NullPointer on for (User user : followers)
and see this link http://grepcode.com/file/repo1.maven.org/maven2/org.twitter4j/twitter4j-examples/2.2.4/twitter4j/examples/list/GetAllUserLists.java here they guided to how to get Users in Java but ResponseList<UserList> lists = twitter.getAllUserLists(args[0]);
in this link what is arg[0] as per method http://twitter4j.org/ja/javadoc/twitter4j/api/ListMethods.html please guide me to solve my problem.
private static final String user ="your-user";
private static final String pw ="your-password";
// Make a Twitter object
Twitter twitter = new TwitterFactory().getInstance(user,pw);
// Set my status
twitter.setStatus("@vogella messing with Twitter in Java");
List<User> followers = twitter.getFollowers();
for (User user : followers) {
System.out.println(user.getName());
}
}
As per my knowledge, Twiiter has updated their apis, now they are supporting oauth 2.0 mechanism to retrieve any info.
To retrieve followers lis you should use below linkhttps://dev.twitter.com/docs/api/1/get/followers/idsyou can use Twitter4j library for java/androidhttp://twitter4j.org/en/index.html
private void twitter_req()
{
String access_token = prefs.getString("twitter_token", null);
String access_secret = prefs.getString("twitter_secret", null);
twitter_api lapi=new twitter_api(access_token,access_secret,new GetUserInfo_TWRequestCallback());
lapi.get("api.twitter.com/1/followers/ids.json ");
}
public void get() {
try {
HttpGet httpRequest = new HttpGet(mUrl);
sign(httpRequest);
sendSync(httpRequest);
} catch(Exception e) {
Log.d(" get()", e.toString());
doFailCallback();
}
}
private void sendSync(HttpRequestBase httpRequest)
{
HttpClient httpClient = new DefaultHttpClient();
HttpResponse httpResponse = httpClient.execute(httpRequest);
StatusLine statusLine = httpResponse.getStatusLine();
HttpEntity entity = httpResponse.getEntity();
//
//
response = "null";
if (entity != null) {
response = getResponseFromStream(entity.getContent()); //
}
}
public void sign(HttpRequestBase httpRequest) throws OAuthMessageSignerException, OAuthExpectationFailedException {
// MSOAuth oauth = MSOAuth.init(mSession);
// oauth.sign(httpRequest);
try {
consumer.sign(httpRequest);
} catch (OAuthCommunicationException e) {
response="errorsign";
if(e!=null)
if(e.getMessage()!=null)
{
response=e.getMessage();
}
// TODO Auto-generated catch block
e.printStackTrace();
}
}
这篇关于我想获取Twitter的追随者,以下列表中的android但是,让空指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!