使用JSON数组Twitter的饲料 [英] twitter feeds using json array

查看:115
本文介绍了使用JSON数组Twitter的饲料的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个应用程序来获取Twitter的饲料。我写了下面

I am developing an application to retrieve Twitter feeds. I wrote the following

try {   
    codeString x = "";
    Twitter y;
    HttpClient pingclient = new DefaultHttpClient();
    HttpPost pingpost = new HttpPost("https://twitter.com/statuses/user_timeline/krish_hari.json");
    pingpost.addHeader("Accepts", "application/json");
    pingpost.addHeader("Content-type", "application/json");

    org.apache.http.HttpResponse pingResponse = pingclient.execute(pingpost);
    HttpEntity loginEntity = pingResponse.getEntity();
    String result = EntityUtils.toString(loginEntity);

    //InputStream is = this.getResources().openRawResource(R.raw.jsontwitter);
    //byte [] buffer = new byte[is.available()];
    //while (is.read(buffer) != -1);
    //String jsontext = new String(buffer);
    JSONArray entries = new JSONArray(result);

    x = "JSON parsed.\nThere are [" + entries.length() + "]\n\n";

    int i;
    for (i=0;i<entries.length();i++) {
        JSONObject post = entries.getJSONObject(i);
        x += "------------\n";
        x += "Date:" + post.getString("created_at") + "\n";
        x += "Post:" + post.getString("text") + "\n\n";
    }
    tvData.setText(x);
}
catch (Exception je) {
    tvData.setText("Error w/file: " + je.getMessage());
}

我得到错误的 错误瓦特/文件:twitter.com 的。谁能帮我破解这个?

I get the error error w/file:twitter.com. Can anyone help me to crack this?

推荐答案

我用这个code检索Twitter的饲料:

I use this code to retrieve Twitter feed:

HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(new HttpGet(url[0]));
InputStream is = response.getEntity().getContent();
BufferedReader br = new BufferedReader(new InputStreamReader(is,"UTF-8"));
StringBuffer sb = new StringBuffer();
try
{
    String line = null;             
    while ((line = br.readLine())!=null)
    {
        sb.append(line);
        sb.append('\n');                
    }
}
catch (IOException e)
{
    e.printStackTrace();
}
String jsontext = new String(sb.toString());

网​​址[0] 是URL的JSON提要。

url[0] is the URL to the JSON feed.

您必须重新格式化您的网址,这种格式你现在用的就是去precated。

You must reformat your URL, this format you're using now is deprecated.

请参阅 https://dev.twitter.com/docs/ API / 1 /获取/状态/ user_timeline

这篇关于使用JSON数组Twitter的饲料的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆