无法通过“HttpURLConnection”获取公共Facebook Feed

时间:2013-03-07 20:15:10

标签: android facebook

以下是我正在尝试做的代码。 我已在清单文件中添加了Internet访问权限。另外,我不希望用户登录facebook;只是希望数据出现。

   public class MainActivity extends Activity {

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            URL url;
            try {
                url = new URL("https://www.facebook.com/feeds/page.php?format=rss20&id=289781571139242");

                HttpURLConnection urlConnection = (HttpURLConnection) url
                        .openConnection();

                InputStream in = urlConnection.getInputStream();

                InputStreamReader isw = new InputStreamReader(in);

                int data = isw.read();
                while (data != -1) {
                    char current = (char) data;
                    data = isw.read();
                    System.out.print(current);
                }
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.activity_main, menu);
            return true;
        }

    }

0 个答案:

没有答案