LikeView回调

时间:2015-01-30 12:17:50

标签: android facebook facebook-android-sdk facebook-likebox

我正在将Facebook LikeView整合到官方fb docs中定义的Android应用程序片段中。

LikeView like_button = (LikeView) findViewById(R.id.like_view);
like_button.setObjectId(...);

我也像这样处理onActivityResult:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

uiHelper.onActivityResult(requestCode, resultCode, data, null);
.....
}

我无法以编程方式查找用户是否喜欢该页面,还是从LikeView中取消了该页面。每当likeview的弹出窗口返回时,onActivityResults会触发,但没有关于结果的信息。

请帮助我确定我缺少的是什么。 任何帮助将不胜感激

2 个答案:

答案 0 :(得分:7)

您可以通过将此代码添加到onActivityResults

来获取用户的操作
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
       default:
            if (resultCode == RESULT_OK) {
                // verify we're returning from like action
                if ("com.facebook.platform.action.request.LIKE_DIALOG".equals(data.getStringExtra("com.facebook.platform.protocol.PROTOCOL_ACTION"))) {
                    // get action results
                    Bundle bundle = data.getExtras().getBundle("com.facebook.platform.protocol.RESULT_ARGS");
                    if (bundle != null) {
                        bundle.getBoolean("object_is_liked"); // liked/unliked
                        bundle.getInt("didComplete");
                        bundle.getInt("like_count"); // object like count
                        bundle.getString("like_count_string");
                        bundle.getString("social_sentence");
                        bundle.getString("completionGesture"); // liked/cancel/unliked
                    }
                }
            }
            break;
}

答案 1 :(得分:0)

希望得到这个帮助。

        private String siLeGusta = "";    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_final);
            ...
            ...

            Session session = Session.getActiveSession(); // si estas en un activity diferente

            String solicitud = "/"+uid+"/likes/"+page_id; //uid=user_id, page_id = el id de la pagina que deseas saber si ya tiene like del usuario.
            new Request(
                    session,
                    solicitud, //"/{user-id}/likes/{page-id}",
                    null,
                    HttpMethod.GET,
                    new Request.Callback() {
                        public void onCompleted(Response response) {
                            GraphObject graphObject = response.getGraphObject();
                            //String s = txtFinal.getText().toString();
                            if (graphObject != null) {
                                JSONObject jsonObject = graphObject.getInnerJSONObject();
                                try {
                                    JSONArray array = jsonObject.getJSONArray("data");
                                    for (int i = 0; i < array.length(); i++) {
                                        JSONObject object = (JSONObject) array.get(i);
                                        siLeGusta = object.get("id").toString();

                                    }
                                } catch (JSONException e) {

                                    e.printStackTrace();
                                }
                            }
                            if (siLeGusta.equals(page_id)){
                                likeView.setVisibility(View.INVISIBLE);
                                txtFinal.setText("A tí te gusta la página de ....");
                                txtFinal.setTextSize(30);

                            }else{
                                txtFinal.setText("Todavía no has dado LIKE a la página de ....");
                                txtFinal.setTextSize(30);
                                likeView.setVisibility(View.VISIBLE);
                            }
                        }
                    }).executeAsync();

... //otras instrucciones aquí.

    }