我在facebook指南之后实现了facebook按钮。它工作正常但是
如first_name,
姓氏,
电子邮件,
性别,
fb_id。
我收到了除电子邮件以外的所有内容。我可能需要给予一些许可但是我找不到它在哪里给它。
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中,我添加了这样的许可
答案 0 :(得分:1)
电子邮件字段不是从我的端点返回的标准字段,因此您需要使用Request类获取特定请求。
在其上设置所需的字段,例如:
// 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();
在此之前你需要电子邮件许可。
您可以使用the graph api explorer查看图表请求的行为。
答案 1 :(得分:-1)
试试这个库,这是处理facebook https://github.com/sromku/android-simple-facebook
的最简单方法