Facebook的SDK 3.5:获取用户数据例如工作在模拟器,但不是在真实设备 [英] Facebook SDK 3.5 : fetch user data example works in emulator but not in real device

查看:442
本文介绍了Facebook的SDK 3.5:获取用户数据例如工作在模拟器,但不是在真实设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现获取用户数据例如给上developers.facebook.com
它工作正常,在logcat的仿真器和数据里显示
但是当我在实际设备尝试它为登录不开屏
这就是为什么它直接写入消息logcat的注销(我想这意味着状态是关闭的)
以下是code

I am trying to implement fetch user data example give on developers.facebook.com It works fine on Emulator and displayes data in logcat but when i try it in real device it doesn't open screen for login thats why it directly writes message to Logcat "Logged out"( I guess that means state is closed) following is the code

私人无效onSessionStateChange(会话的会话,SessionState会状态,异常除外){

private void onSessionStateChange(Session session, SessionState state, Exception exception) {

if (state.isOpened()) {
           Log.i(TAG, "Logged in...");
        userInfoTextView.setVisibility(View.VISIBLE);

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

              // callback after Graph API response with user object
          @Override
          public void onCompleted(GraphUser user, Response response) {

      if (user != null) {
                // Display the parsed user info
                buildUserInfoDisplay(user);
                Log.d(TAG,"Data Displayed");
            }
          }
        }).executeAsync();

    } else if (state.isClosed()) {
        Log.i(TAG, "Logged out...");
        userInfoTextView.setVisibility(View.INVISIBLE);
    }
}

@Override
public View onCreateView(LayoutInflater inflater, 
        ViewGroup container, 
        Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fblogin, container, false);
    LoginButton authButton = (LoginButton) view.findViewById(R.id.authButton);
    authButton.setFragment(this);
    authButton.setReadPermissions(Arrays.asList("user_likes", "user_status","user_location","email","user_birthday"));
    Log.d(TAG,"onCreateview");

    userInfoTextView = (TextView) view.findViewById(R.id.userInfoTextView);

    return view;

}

private Session.StatusCallback callback = new Session.StatusCallback() {
    @Override
    public void call(Session session, SessionState state, Exception exception) {
        onSessionStateChange(session, state, exception);
    }
};

@Override
public void onResume() {
    super.onResume();
    // For scenarios where the main activity is launched and user
    // session is not null, the session state change notification
    // may not be triggered. Trigger it if it's open/closed.
    Session session = Session.getActiveSession();
    if (session != null &&
           (session.isOpened() || session.isClosed()) ) {
        onSessionStateChange(session, session.getState(), null);
    }

    uiHelper.onResume();
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    uiHelper.onActivityResult(requestCode, resultCode, data);
}

@Override
public void onPause() {
    super.onPause();
    uiHelper.onPause();
}

@Override
public void onDestroy() {
    super.onDestroy();
    uiHelper.onDestroy();
}

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    uiHelper.onSaveInstanceState(outState);
}

private void buildUserInfoDisplay(GraphUser user) {
    /*if(user.getLocation()!=null){
    userInfo.append(String.format("ID: %s\n\n", 
            user.getLocation()));
    }*/
    //Log.d(TAG+" Location",user.getLocation().toString());

    Map<String, String> map;
    map = new HashMap<String, String>();

    try {
        map.put("ID", user.getId().toString());
        map.put("email", user.getProperty("email").toString());
        map.put("rel status", user.getProperty("relationship_status")
                .toString());
        map.put("name", user.getName().toString());
        // - requires user_birthday permission
        map.put("birthday", user.getBirthday().toString());
        map.put("gender", user.getProperty("gender").toString());
    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
        Log.d(TAG,"Info is: "+map);
    }
}}

我已经安装在设备的Facebook应用程序,但它不会从应用程序启动的登录也。
我要补充一些不同的东西,以获得的WebView或登录屏幕登录。

I have facebook app installed in device but it doesn't initiate login from that app also. do I have to add something different in order to get webview or login screen for login.

请注意,这code在仿真器的工作原理:
感谢您的帮助。

Note that this code works in emulator: Thanks for the help

推荐答案

Facebook的SDK中最常见的错误之一是得到了debug.keystore但不能用于分配密钥存储在Android keyhash。

one of the most common pitfalls of the Facebook SDK is to get the Android keyhash for the debug.keystore but not for the distribution keystore.

我asume,如果您的应用程序上汇入作业模拟器的工作汇入作业,因为你已经确立了自己debug.keystore哈希上Facebook的开发者网站上的Facebook应用程序的配置。

I asume that if your app it´s working on your emulator it´s because you have set your debug.keystore hash on your Facebook app configuration on the Facebook Developer site.

您只需要运行在终端上这一行:

You just need to run this line on the terminal:

keytool -exportcert -alias androireleasekey -keystore PATH_TO_THE_RELEASE_KEYSTORE | openssl sha1 -binary | openssl base64

和把它的应用程序配置(Facebook的开发者网站)旁边的调试之一。

And put it on the app configuration (Facebook Developers site) next to the debug one.

希望它帮助! :)

这篇关于Facebook的SDK 3.5:获取用户数据例如工作在模拟器,但不是在真实设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆