Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Android布局中从Facebook获取提要_Android_Facebook_Facebook Graph Api - Fatal编程技术网

在Android布局中从Facebook获取提要

在Android布局中从Facebook获取提要,android,facebook,facebook-graph-api,Android,Facebook,Facebook Graph Api,我正在尝试将我的应用程序与社交网络(facebook和twitter)集成 我想拥有访问权限,例如用户墙或公共墙,并将其发布在我的布局中,如滚动视图或项目视图(或任何建议!!!),这在twitter上得到了解决,但我无法将这项工作放到facebook上 我使用图形API 要在我的墙中发布帖子,我创建了方法postTextOnMyWall: public String postTextOnMyWall(String message) { Log.d("Tests", "T

我正在尝试将我的应用程序与社交网络(facebook和twitter)集成

我想拥有访问权限,例如用户墙或公共墙,并将其发布在我的布局中,如滚动视图或项目视图(或任何建议!!!),这在twitter上得到了解决,但我无法将这项工作放到facebook上

我使用图形API

要在我的墙中发布帖子,我创建了方法postTextOnMyWall

    public String postTextOnMyWall(String message) {

        Log.d("Tests", "Testing graph API wall post");
        try {
            Bundle parameters = new Bundle();
            parameters.putString("message", message);// key/value
            this.mAsyncRunner.request("me/feed", parameters, "POST",
                    new WallPostTextRequestListener(), null);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return message;
    }

    public AsyncFacebookRunner getmAsyncRunner() {
        return this.mAsyncRunner;
    }

    public void setmAsyncRunner(AsyncFacebookRunner mAsyncRunner) {
        this.mAsyncRunner = mAsyncRunner;
    }
}
此方法作为发布文本消息的侦听器,WallPostTextRequestListener

    public class WallPostTextRequestListener implements RequestListener {

    public void showToast(String message) {
        Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT)
                .show();
    }

    // called on successful completion of the Request
    @Override
    public void onComplete(String response, Object state) {
        Log.d("WallPostTextRequestListener", "Got response: " + response);
        String message = "<empty>";
        try {
            JSONObject json = Util.parseJson(response);
            message = json.getString("message");
            showToast("Mensagem escrita no teu mural facebook!: " + message);
        } catch (JSONException e) {
            Log.e("WallPostTextRequestListener", "JSON Error in response");
        } catch (FacebookError e) {
            Log.e("WallPostTextRequestListener",
                    "Facebook Error: " + e.getMessage());
        }
        final String text = "Mensagem: " + message;
    }

    @Override
    public void onIOException(IOException e, Object state) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onFileNotFoundException(FileNotFoundException e,
            Object state) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onMalformedURLException(MalformedURLException e,
            Object state) {
        // TODO Auto-generated method stub

    }

    // called if there is an error
    @Override
    public void onFacebookError(FacebookError e, Object state) {
        // TODO Auto-generated method stub

    }

}
如何从我的墙或公共页面获取提要?
提前谢谢

经过一段时间的思考,我和一位同事一起找到了解决方案

我们将创建一个HashMap,并向其传递两个字符串,例如,一个用于评论,另一个用于文章作者。之后,我们将在上面的方法onComplete的末尾创建另一个活动的意图,因此这必须看起来像这样:

public void onComplete(String response, Object state) {
        Log.d("getFeedfromWallRequestListener", "Got response: "
                + response);
        try {
            JSONObject json = Util.parseJson(response);
            Log.d("TESTE", "MY FEED EM JSON: " + json);

            String comments;
            String names;
        //Show all the comments and names
            JSONArray jArray=(JSONArray)json.get("data");
            for(int i=0;i<(jArray.length());i++)
            {
                 //jArray.getJSONObject(i).getJSONObject("from").get("name");   
                 //jArray.getJSONObject(i).get("message");
                HashMap<String, String> map = new HashMap<String, String>();

                 comments =   jArray.getJSONObject(i).get("message").toString();
                 names =   jArray.getJSONObject(i).getJSONObject("from").get("name").toString();
                    map.put("comments", comments);
                    map.put("names", names);
                    mylist.add(map);


                 Log.d("NAMES","Names: " + names);
                 Log.d("Comments","Comments: " + comments);

            }                       
            //showToast("Json com resposta do teu mural facebook!: " + json);
        } catch (JSONException e) {
            Log.w("getFeedfromWallRequestListener",
                    "JSON Error in response");
        } catch (FacebookError e) {
            Log.w("getFeedfromWallRequestListener", "Facebook Error: "
                    + e.getMessage());
        }
        Intent intent = new Intent("android.intent.action.FacebookList");
        intent.putExtra("arraylist", mylist);

        try {
            Log.i("TAG", "starting activity(android.intent.action.FacebookList)");
            /*
             * 
             */
            startActivity(intent);
        } catch (Exception e) {
            Log.e("TAG", "error when trying to start activity: " + e.getMessage());
            for (int n = 0; n < e.getStackTrace().length; n++) {
                Log.e("TAG", "stack: " + e.getStackTrace()[n].toString());
            }
        }


    }
public void onComplete(字符串响应、对象状态){
Log.d(“getFeedfromWallRequestListener”,“获得响应:”
+反应);
试一试{
JSONObject json=Util.parseJson(响应);
Log.d(“TESTE”,“MY FEED EM JSON:+JSON”);
字符串注释;
字符串名;
//显示所有注释和名称
JSONArray jArray=(JSONArray)json.get(“数据”);
对于(int i=0;i
public void onComplete(String response, Object state) {
        Log.d("getFeedfromWallRequestListener", "Got response: "
                + response);
        try {
            JSONObject json = Util.parseJson(response);
            Log.d("TESTE", "MY FEED EM JSON: " + json);

            String comments;
            String names;
        //Show all the comments and names
            JSONArray jArray=(JSONArray)json.get("data");
            for(int i=0;i<(jArray.length());i++)
            {
                 //jArray.getJSONObject(i).getJSONObject("from").get("name");   
                 //jArray.getJSONObject(i).get("message");
                HashMap<String, String> map = new HashMap<String, String>();

                 comments =   jArray.getJSONObject(i).get("message").toString();
                 names =   jArray.getJSONObject(i).getJSONObject("from").get("name").toString();
                    map.put("comments", comments);
                    map.put("names", names);
                    mylist.add(map);


                 Log.d("NAMES","Names: " + names);
                 Log.d("Comments","Comments: " + comments);

            }                       
            //showToast("Json com resposta do teu mural facebook!: " + json);
        } catch (JSONException e) {
            Log.w("getFeedfromWallRequestListener",
                    "JSON Error in response");
        } catch (FacebookError e) {
            Log.w("getFeedfromWallRequestListener", "Facebook Error: "
                    + e.getMessage());
        }
        Intent intent = new Intent("android.intent.action.FacebookList");
        intent.putExtra("arraylist", mylist);

        try {
            Log.i("TAG", "starting activity(android.intent.action.FacebookList)");
            /*
             * 
             */
            startActivity(intent);
        } catch (Exception e) {
            Log.e("TAG", "error when trying to start activity: " + e.getMessage());
            for (int n = 0; n < e.getStackTrace().length; n++) {
                Log.e("TAG", "stack: " + e.getStackTrace()[n].toString());
            }
        }


    }
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">    

<ListView
    android:id="@id/android:list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:drawSelectorOnTop="false" />

<TextView
    android:id="@id/android:empty"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="No data"/>
import java.util.ArrayList;
import java.util.HashMap;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class FacebookList extends ListActivity{

  /** Called when the activity is first created. */

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.listplaceholder);

    ArrayList<HashMap<String, String>> arl =(ArrayList<HashMap<String, String>>) getIntent().getSerializableExtra("arraylist");
    System.out.println("...serialized data.."+arl);


    ListAdapter adapter = new SimpleAdapter(this, arl , R.layout.list_main, 
            new String[] { "comments", "names" }, 
            new int[] { R.id.item_title, R.id.item_subtitle });

    ListView listView = getListView();
    listView.setAdapter(adapter);
    listView.setTextFilterEnabled(true);

    listView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            // When clicked, show a toast with the TextView text
            Toast.makeText(getApplicationContext(),
            ((TextView) view).getText(), Toast.LENGTH_SHORT).show();
        }
    });
}
}