【问题标题】:Twitter App in Processing处理中的 Twitter 应用程序
【发布时间】:2013-04-03 02:31:56
【问题描述】:

我正在尝试创建的 Twitter 应用程序存在严重问题。我已经连续两周解决这个问题,每天 14 小时,我无法弄清楚如何解决。我是新手,所以我相信这只是一件简单的事情。

我需要我的推特流一次显示五条推文。然后我需要它删除最旧的推文并用新的推文替换它。现在有人告诉我最好的方法是使用 Linkedlist,这很有意义。但是,每当我尝试合并它时,它都行不通。

如果有人可以帮助我,我将不胜感激,因为此时我已经束手无策了。

代码如下:

import com.francisli.processing.http.*;

import java.util.LinkedList;

//LinkedList myList;


HashMap overall = new HashMap();


HttpClient client;

LinkedList myList;



PImage prhomoPix;

int results_to_show = 5;
int updateTime = 10000;
int updateDiff = 0;



void setup()
{

 myList = new LinkedList();
 for (int i = 0; i < 5; i++) 
 {
   myList.add(client);
 }

  size(1143, 800);



  prhomoPix = loadImage("PrhomoAppBg.jpg");

  background(0);
  image(prhomoPix, 0, 0);


  fill(0, 0, 0, 80);
  noStroke();
  rect(20, 135, 370, 670);

  fill(0, 0, 0, 80);
  noStroke();
  rect(755, 135, 370, 670);

  textAlign(CENTER, CENTER);

}






void responseReceived(HttpRequest request, HttpResponse response)
{


 if(response.statusCode == 200)
 {

    JSONObject allresults;
    allresults = response.getContentAsJSONObject();
    //JSONObject timeline_tweets = response.getContentAsJSONObject();






  for (int i = 0; i < 5; i++)
 {

    text(allresults.get("results").get(i).get("text").stringValue(), 25, 50+(i*120), 330, 330);

  }
  frameRate(2);




//}



   //for (int i=0; i < results_to_show; i++)
  //{

  // text(allresults.get("results").get(i).get("text").stringValue(), 25, 50+(i*120), 330, 330);
 // }

}

      else
  {
    text("UH-OH" + response.getContentAsString(), 50, 50);
  } 
}


void tweetUpdate()
{

  if(millis() > (updateTime + updateDiff))
  {


    client = new HttpClient(this, "search.twitter.com");//what webservice we are using, this is the priate OAuth one. "this" means it is not cpying setting from anywhere else
    client.GET("search.json?q=dublin&rpp="+results_to_show+"&result_type=recent");





    //println(myList);

    updateDiff = millis();

  }  

 }




   void draw()
{
 myList.remove(client);
 myList.add(client);
 tweetUpdate(); 

}

再次非常感谢!

【问题讨论】:

  • 如果您实际上已经为此花费了大约 200 个小时,那么您下次应该尽早寻求帮助。你会更有效率。
  • 我已经有了,这是我从那里得到链接列表的地方。我最近才发现这个网站。
  • 另外,很抱歉用这个问题打扰大家。除非我 100% 确定自己被卡住了,否则我不会占用论坛空间

标签: api twitter processing


【解决方案1】:

老实说,Java 确实不是我的领域,但这些教程看起来很不言自明。希望他们有所帮助。

http://examples.javacodegeeks.com/core-java/util/linkedlist/

【讨论】:

    【解决方案2】:
    1. 您必须在draw() 方法中重新绘制整个屏幕。
    2. 我猜,人们告诉过你将 tweets 保存在 LinkedList,而不是 HttpClient
    3. 更新responseReceived() 方法中的推文列表。

    最终,你的画会看起来像这样:

    void draw() {
      // repaint
      background(0);
      // draw picture
      image(prhomoPix, 0, 0);
      // repaint all tweets
      for(int i=0; i< tweetsList.size(); ++i {
        drawTweet(tweetsList);
      }
      tweetUpdate(); // update list of tweets from server
    }
    

    tweetUpdate()

    void tweetUpdate() {
        client = new HttpClient(this, "search.twitter.com");
        client.GET("search.json?q=dublin&rpp="+results_to_show+"&result_type=recent");
    }
    

    【讨论】:

      猜你喜欢
      • 2013-03-21
      • 2012-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-09
      • 2014-02-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多