如何使用facebook sdk for android从Facebook获得用户的兴趣

时间:2013-09-27 10:13:12

标签: android facebook-graph-api facebook-android-sdk

我在我的应用程序中使用facebook sdk并获取详细信息,如facebook_id,dob,email_id,用户名等。我正在获取所有这些详细信息并在我的应用程序中使用它们但事情是现在我想获取的兴趣登录用户,但我没有得到相同的,不知道发生了什么。

我获取所有这些细节的代码如下: -

Session.openActiveSession(context, true, new Session.StatusCallback() {

                @Override
                public void call(final Session session, SessionState state, Exception exception) {
                    // TODO Auto-generated method stub
                    if(session.isOpened())
                    {
                        showToast("Please wait");
                        List<String> permissions = session.getPermissions();

                        if (!isSubsetOf(PERMISSIONS, permissions)) {
                            pendingPublishReauthorization = true;
                            Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(context, PERMISSIONS);
                            session.requestNewPublishPermissions(newPermissionsRequest);
                        }

                        Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {

                            @Override
                            public void onCompleted(GraphUser user, Response response) {
                                // TODO Auto-generated method stub
                                if(user!=null)
                                {

                                    try{
                                        Log.d("", "Fb responcse == "+response.toString());
                                        Log.d("", "FbUser >> "+ user.toString());
                                        fbUserid=user.getId();
                                        fbAccessToken=session.getAccessToken();
                                        Log.i("User Name ", "FbName : "+user.getName());
                                        Log.i("User Id ", "FbId : "+user.getId());
                                        Log.i("User Id ", "FbLocation : "+user.getLocation().toString());

                                        Log.i("User Id ", "FbEmailId : "+user.getLink());
                                        Log.i("User Id ", "FbDob : "+user.getBirthday());

                                        Log.i("User Id ", "FbGender : "+user.asMap().get("gender").toString());
                                        Log.i("User Id ", "FbEmail : "+user.getProperty("email").toString());
                                        //Log.i("User Id ", "FbCity : "+user.getLocation().getCity().toString());
                                        //Log.i("User Id ", "FbState : "+user.getLocation().getState().toString());
                                        Log.i("User Access Token ", "FbAccess Token : "+session.getAccessToken());

                                        Log.i("USER LIKES", "USER LIKES" + user.getLink().toString());

                                        String fqlQuery = "SELECT music, books, movies FROM user where uid ="+user.getId();
                                        Bundle bundle = new Bundle();
                                        bundle.putString("q", fqlQuery);
                                        Request request = new Request(session, "/fql", bundle, HttpMethod.GET, 
                                            new Request.Callback() {
                                                @Override
                                                public void onCompleted(Response response) {
                                                    // TODO Auto-generated method stub
                                                    Log.i("INFO", response.toString());
                                                }
                                            });
                                        Request.executeBatchAsync(request);

                                        pBar.setVisibility(View.INVISIBLE);

                                        String name = user.getName();
                                        String dob = user.getBirthday();
                                        gender = user.asMap().get("gender").toString();

                                        if(gender.equalsIgnoreCase("male")){

                                            genMale.setChecked(true);
                                            //genFemale.setSelected(false);
                                            //Toast.makeText(context, "male", 0).show();
                                        }
                                        else{

                                            //genMale.setSelected(false);
                                            genFemale.setChecked(true);
                                            //Toast.makeText(context, "female", 0).show();

                                        }

                                        String email =user.getProperty("email").toString();
                                        String city = user.getLocation().getProperty("name").toString();
                                        String url="http://graph.facebook.com/"+user.getId()+"/picture?type=large";
                                        setText(name, dob, email, city, "","",url);

                                        userIdFB = user.getId();

                                        accessTokenFB = session.getAccessToken();

                                    }catch(Exception ex){
                                        ex.printStackTrace();
                                    }


                                }

                                else{
                                    pBar.setVisibility(View.INVISIBLE);
                                    Log.i("ELSE", "ELSE");
                                }
                            }


                        });
                        //session.getAccessToken();
                        //Toast.makeText(context, "Session AccessToken : "+session.getAccessToken(), Toast.LENGTH_LONG).show();
                    }

                    if(session.isClosed()){

                        //Toast.makeText(context, "Closed", 0).show();
                    }

                }


            });

所以问题是我应该添加什么才能让我能够获得当前登录用户的所有兴趣。 请帮助我解决这个问题。任何帮助都会很明显。

提前致谢。

0 个答案:

没有答案