3

我在我的应用程序中设置了 facebook 登录,如下所示,想法是先登录,然后执行一个操作GraphUserCallback,这样我们就可以获得使用信息,然后传递到我自己的注册系统,这样就可以为我的应用程序设置一个用户帐户。

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

                    @Override
                    public void onCompleted(GraphUser user,
                            Response response) {

                        if (dialog != null && dialog.isShowing()) {
                            dialog.dismiss();
                        }
                        if (user != null) {
                            Map<String, Object> responseMap = new HashMap<String, Object>();
                            GraphObject graphObject = response
                                    .getGraphObject();
                            responseMap = graphObject.asMap();
                            Log.i("FbLogin", "Response Map KeySet - "
                                    + responseMap.keySet());

                            Session session = Session.getActiveSession();
                            String email = null;
                            String token = null;
                            String username = null;
                            String gender = null;
                            String birthday = null;
                            if (responseMap.get("email") != null) {
                                email = responseMap.get("email").toString();
                                username = responseMap.get("first_name").toString()+" "+responseMap.get("last_name").toString();
                                gender = responseMap.get("gender").toString();
                                token = session.getAccessToken();
                                /*birthday = responseMap.get("user_birthday").toString();

                                Context context = getApplicationContext();
                                int duration = Toast.LENGTH_SHORT;

                                Toast toast = Toast.makeText(context, birthday, duration);
                                toast.show();*/

                                Intent i = new Intent(LogIn.this, FbLogin2Activity.class);
                                i.putExtra("Email", email);
                                i.putExtra("Token", token);
                                i.putExtra("Username", username);
                                i.putExtra("Gender", gender);
                                startActivity(i);
                            } else {
                                // Clear all session info & ask user to
                                // login again
                                if (session != null) {
                                    session.closeAndClearTokenInformation();
                                }
                            }
                        }
                    }
                });

当用户单击“登录”按钮时:

fblogin.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                Session session = Session.getActiveSession();
                if (session == null) {
                    Session.openActiveSession(LogIn.this, true,
                            statusCallback);
                } else if (!session.isOpened()) {
                    session.openForRead(new Session.OpenRequest(
                            LogIn.this).setCallback(statusCallback)
                            .setPermissions(permissions)
                            );
                }
                /*Intent i = new Intent(getApplicationContext(), FbLoginActivity.class);
                startActivity(i);*/
            }
        });

我的权限是:

/***** FB Permissions *****/
permissions = new ArrayList<String>();
permissions.add("email");
permissions.add("user_birthday");
permissions.add("user_location");
/***** End FB Permissions *****/

用户的电子邮件被返回并且可以工作,但是用户的电子邮件或位置都不在 graphusecallback 响应中。

不确定我是否已经发布了所有需要的内容,所以请告诉我,但我不知道为什么它不返回所有内容

4

1 回答 1

1

用户的生日将在该birthday字段中,用户的位置将在该location字段中(与user_birthdayor相对user_location)。所以

birthday = responseMap.get("birthday").toString();
location = responseMap.get("location").get("name").toString();

应该管用。

于 2013-10-18T20:21:31.597 回答