与电子邮件的反响Facebook的登录按钮 [英] Facebook Login Button with email responce

查看:137
本文介绍了与电子邮件的反响Facebook的登录按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已实施以下Facebook的按钮,Facebook的guide.It的完美工作,但

I had implemented the facebook button following the facebook guide.It's working perfectly but

FIRST_NAME,

first_name,

姓氏,

电子邮件

性别,

fb_id。

我得到了电子邮件以外的东西全部 .Might是我需要给一些权限,但我找不到它的地方给它。

I got all the things except email.Might be I need to give some permission But I can't find it where to give it.

MainActivity.class

public class MainActivity extends FragmentActivity {

private MainFragment mainFragment;
private LoginButton loginBtn;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);

    loginBtn = (LoginButton) findViewById(R.id.fb_login_button);
    loginBtn.setUserInfoChangedCallback(new UserInfoChangedCallback() 
    {
        @Override
        public void onUserInfoFetched(GraphUser user) 
        {
            if (user != null) 
            {
                Intent i = new Intent(MainActivity.this, RegistrationActivity.class);
                i.putExtra("first_name", user.getFirstName());
                i.putExtra("last_name", user.getLastName());
                //i.putExtra("email", user.asMap().get("email").toString());
                i.putExtra("sex", user.asMap().get("gender").toString());
                i.putExtra("fb_id", user.getId());

                Log.i("first_name", user.getFirstName());
                Log.i("last_name", user.getLastName());
                //Log.i("email", user.getProperty("email").toString());
                Log.i("sex", user.asMap().get("gender").toString());
                Log.i("fb_id", user.getId());

                finish();
                startActivity(i);

            } 
            else 
            {
                Log.i("TAG", "You are not logged");
            }
        }
    });

    if (savedInstanceState == null) 
    {
        // Add the fragment on initial activity setup
        mainFragment = new MainFragment();
        getSupportFragmentManager()
        .beginTransaction()
        .add(android.R.id.content, mainFragment)
        .commit();
    }
    else 
    {
        // Or set the fragment from restored state info
        mainFragment = (MainFragment) getSupportFragmentManager()
                .findFragmentById(android.R.id.content);
    }
}

public void goingToRegister(View v) 
{
    v.findViewById(R.id.buttonRegister).startAnimation(AnimationUtils.loadAnimation(MainActivity.this, R.anim.image_click));

    Intent i = new Intent(MainActivity.this, RegistrationActivity.class);
    finish();
    startActivity(i);
}

public void loginNow(View v) 
{
    v.findViewById(R.id.buttonLogin).startAnimation(AnimationUtils.loadAnimation(MainActivity.this, R.anim.image_click));

    Intent i = new Intent(MainActivity.this, LoginActivity.class);
    finish();
    startActivity(i);
}
}

MainFragment.class

public class MainFragment extends Fragment {

private static final String TAG = "MainFragment";
private UiLifecycleHelper uiHelper;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
{
    View view = inflater.inflate(R.layout.main_activity, container, false);


    LoginButton authButton = (LoginButton) view.findViewById(R.id.fb_login_button);
    authButton.setReadPermissions(Arrays.asList("public_profile","email","user_friends"));
    authButton.setFragment(this);

    return view;
}

private void onSessionStateChange(Session session, SessionState state, Exception exception) 
{
    if (state.isOpened()) 
    {
        Log.i(TAG, "Logged in...");
    } 
    else if (state.isClosed()) 
    {
        Log.i(TAG, "Logged out...");
    }
}

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


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    uiHelper = new UiLifecycleHelper(getActivity(), callback);
    uiHelper.onCreate(savedInstanceState);
}

@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);

    Log.i("TAG", "responce: " + 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);
}
}

在Facebook上加我这样的权限

In facebook I added the permission like this

推荐答案

电子邮件字段是不是从我的终点返回一个标准,所以你需要一个特定的请求使用Request类拿来。

The email field is not a standard one that is returned from the me endpoint, so you will need a specific Request to fetch it using the Request class.

使用此<一个href=\"https://github.com/facebook/facebook-android-sdk/blob/master/facebook/src/com/facebook/Request.java#L278\" rel=\"nofollow\">https://github.com/facebook/facebook-android-sdk/blob/master/facebook/src/com/facebook/Request.java#L278

设置你想要的,喜欢它的字段:

Set the fields on it that you want, like:

// Make sure the user is logged in first
Request meRequest = Request.newMeRequest(Session.getActiveSession(), yourCallback);
Bundle parameters = new Bundle();
// The fields you want in comma separated list
parameters.putString(fields, "id,name,email");
meRequest.setParameters(parameters);
meRequest.executeAsync();

您需要的电子邮件许可的作品,虽然之前。

You need the email permission before that works though.

您可以使用图形API探险以查看该图的要求应该表现。

You can use the graph api explorer to see for the graph request should behave.

这篇关于与电子邮件的反响Facebook的登录按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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