2012-02-29 32 views
1

我想獲取twitter關注者用戶列表,爲什麼我使用以下代碼,但在for (User user : followers)上給予NullPointer,並在此處看到此鏈接http://grepcode.com/file/repo1.maven.org/maven2/org.twitter4j/twitter4j-examples/2.2.4/twitter4j/examples/list/GetAllUserLists.java他們指導如何獲取用戶在Java中,但ResponseList<UserList> lists = twitter.getAllUserLists(args[0]);在這個鏈接是什麼arg [0]按照方法http://twitter4j.org/ja/javadoc/twitter4j/api/ListMethods.html請指導我解決我的問題。我想在android中獲取Twitter關注者和關注列表但是獲取NullPointer

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()); 
    } 
} 
+0

brione/Brion-Learns-OAuth但我想跟隨者和以下列表 – 2012-03-01 07:27:10

回答

4

據我所知,Twiiter更新了他們的apis,現在他們支持oauth 2.0機制來檢索任何信息。

要檢索的追隨者LIS,你應該使用下面的鏈接 https://dev.twitter.com/docs/api/1/get/followers/ids 你可以通過這個我能得到的所有帖子https://github.com/使用的Java庫Twitter4j /安卓 http://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(); 
     } 
} 
+0

是他們的任何例子? – 2012-03-01 05:27:26

+0

嘗試鏈接的例子@鏈接http://twitter4j.org/en/code-examples.html – Maneesh 2012-03-01 06:07:19

+0

老兄試過,但我想通過這個我的追隨者名單我能夠得到所有POst https://github.com/brione/Brion-Learns-OAuth但我想追隨者和以下列表 – 2012-03-01 07:26:45

0

我不知道該API,但它似乎並不清楚根據javadoc返回的列表是否可以爲null或不是。檢查它是否在循環之前。

+0

表哥,它不是一個很好的主意,因爲它可能不是一個好主意,因爲它可能不是一個好主意打電話給國際英語的人哥哥 – Snicolas 2012-02-29 15:10:22

+0

好吧如果你不喜歡 – 2012-02-29 15:18:13

+0

別擔心。它有幫助嗎? – Snicolas 2012-02-29 15:23:23

相關問題