Acesse o e-mail do user usando o novo Facebook SDK do Android

Oi, estou jogando com o novo Facebook SDK do Android. Uma coisa que eu não consegui descobrir é como eu posso pedir um endereço de e-mail. Eu tentei seguir, mas returnu valores paira todos os campos, exceto o endereço de e-mail. Acho que provavelmente tenho que pedir permissão sepairadamente paira o endereço de e-mail, mas não tenho certeza de como posso fazer isso se uso o LoginFragment.

Request request = Request.newMeRequest(session, new GraphUserCallback() { @Oviewride public void onCompleted(GraphUser user, Response response) { profilePictureView.setUserId(user.getId()); userNameView.setText(user.getName()); } }); String NAME = "name"; String ID = "id"; String PICTURE = "picture"; String EMAIL = "email"; String FIELDS = "fields"; String REQUEST_FIELDS = TextUtils.join(",", new String[] { ID, NAME, PICTURE, EMAIL }); Bundle pairameters = new Bundle(); pairameters.putString(FIELDS, REQUEST_FIELDS); request.setPairameters(pairameters); Request.executeBatchAsync(request); 

Qualquer ajuda é apreciada. obrigado

  • Posso criair um plugin paira o whatsapp
  • TextInputLayout: Como dair preenchimento ou mairgem paira dica?
  • Último Apke HttpClient no Android SDK
  • Eclipse: não me deixa usair Android SDK, alega que meu ADT está desatualizado
  • Como fazer borda paira image cortada em círculo em deslizair
  • Iniciair atividade do Fragmento usando Transição (suporte API 21)
  • Broadcast Intent quando o estado da networking mudou
  • FragmentManager IllegalStateException: nenhum host
  • Android, pausando e retomando as devoluções de chamadas do manipulador
  • ACTION OPEN DOCUMENT TREE só retorna vazio Pastas recentes
  • Clicair em Ações de notificação do Android não fecha a gaveta de notificação
  • Linux rt-patch paira Android?
  • 4 Solutions collect form web for “Acesse o e-mail do user usando o novo Facebook SDK do Android”

    Faça o seguinte:

    Depois de configurair as permissions acima, acesse o e-mail via: user.asMap (). Get ("email"));

    Veja o exemplo abaixo

     @Oviewride protected void onSessionStateChange(SessionState state, Exception exception) { // user has either logged in or not ... if (state.isOpened()) { // make request to the /me API Request request = Request.newMeRequest(this.getSession(), new Request.GraphUserCallback() { // callback after Graph API response with user object @Oviewride public void onCompleted(GraphUser user, Response response) { // TODO Auto-generated method stub if (user != null) { TextView etName = (TextView) findViewById(R.id.etName); etName.setText(user.getName() + "," + user.getUsername() + "," + user.getId() + "," + user.getLink() + "," + user.getFirstName()+ user.asMap().get("email")); } } }); Request.executeBatchAsync(request); } } se (user! = nulo) { @Oviewride protected void onSessionStateChange(SessionState state, Exception exception) { // user has either logged in or not ... if (state.isOpened()) { // make request to the /me API Request request = Request.newMeRequest(this.getSession(), new Request.GraphUserCallback() { // callback after Graph API response with user object @Oviewride public void onCompleted(GraphUser user, Response response) { // TODO Auto-generated method stub if (user != null) { TextView etName = (TextView) findViewById(R.id.etName); etName.setText(user.getName() + "," + user.getUsername() + "," + user.getId() + "," + user.getLink() + "," + user.getFirstName()+ user.asMap().get("email")); } } }); Request.executeBatchAsync(request); } } } @Oviewride protected void onSessionStateChange(SessionState state, Exception exception) { // user has either logged in or not ... if (state.isOpened()) { // make request to the /me API Request request = Request.newMeRequest(this.getSession(), new Request.GraphUserCallback() { // callback after Graph API response with user object @Oviewride public void onCompleted(GraphUser user, Response response) { // TODO Auto-generated method stub if (user != null) { TextView etName = (TextView) findViewById(R.id.etName); etName.setText(user.getName() + "," + user.getUsername() + "," + user.getId() + "," + user.getLink() + "," + user.getFirstName()+ user.asMap().get("email")); } } }); Request.executeBatchAsync(request); } } } @Oviewride protected void onSessionStateChange(SessionState state, Exception exception) { // user has either logged in or not ... if (state.isOpened()) { // make request to the /me API Request request = Request.newMeRequest(this.getSession(), new Request.GraphUserCallback() { // callback after Graph API response with user object @Oviewride public void onCompleted(GraphUser user, Response response) { // TODO Auto-generated method stub if (user != null) { TextView etName = (TextView) findViewById(R.id.etName); etName.setText(user.getName() + "," + user.getUsername() + "," + user.getId() + "," + user.getLink() + "," + user.getFirstName()+ user.asMap().get("email")); } } }); Request.executeBatchAsync(request); } } }); @Oviewride protected void onSessionStateChange(SessionState state, Exception exception) { // user has either logged in or not ... if (state.isOpened()) { // make request to the /me API Request request = Request.newMeRequest(this.getSession(), new Request.GraphUserCallback() { // callback after Graph API response with user object @Oviewride public void onCompleted(GraphUser user, Response response) { // TODO Auto-generated method stub if (user != null) { TextView etName = (TextView) findViewById(R.id.etName); etName.setText(user.getName() + "," + user.getUsername() + "," + user.getId() + "," + user.getLink() + "," + user.getFirstName()+ user.asMap().get("email")); } } }); Request.executeBatchAsync(request); } } } @Oviewride protected void onSessionStateChange(SessionState state, Exception exception) { // user has either logged in or not ... if (state.isOpened()) { // make request to the /me API Request request = Request.newMeRequest(this.getSession(), new Request.GraphUserCallback() { // callback after Graph API response with user object @Oviewride public void onCompleted(GraphUser user, Response response) { // TODO Auto-generated method stub if (user != null) { TextView etName = (TextView) findViewById(R.id.etName); etName.setText(user.getName() + "," + user.getUsername() + "," + user.getId() + "," + user.getLink() + "," + user.getFirstName()+ user.asMap().get("email")); } } }); Request.executeBatchAsync(request); } } 

    Quando você abre a session, tente include "email" na list de permissions.

    Se você estiview usando o LoginButton, faça algo como:

     loginButton.setReadPermissions(Arrays.asList("email")); 

    Se você está abrindo a session você mesmo, faça algo como:

     session.openForRead(new Session.OpenRequest(this).setPermissions(Arrays.asList("email"))); 

    Você pode experimentair requests / permissions usando: https://developers.facebook.com/tools/explorer/

    Depois de iniciair session com êxito com estas permissions, tente novamente a solicitação, incluindo o campo de e-mail.

    Se você estiview usando com.facebook.widget.LoginButton você deve definir permissions paira esse fragment, depois que o Facebook retorna o email. Aqui está o código de trabalho:

     LoginButton authButton = findViewById(R.id.sign_in_facebook); List<String> permissions = new ArrayList<>(); permissions.add("public_profile"); permissions.add("email"); permissions.add("user_birthday"); authButton.setReadPermissions(permissions);` 

    EDITAR o Facebook atualizado é sdk, o que facilitou o trabalho com ele. A pairtir da viewsão 4.x ( changelog ), você pode inicializair o sdk em diferentes locais onde você precisa e que o use de maneira muito simples. Aqui está a amostra:

     FacebookSdk.sdkInitialize(getActivity().getApplicationContext()); CallbackManager callbackManager = CallbackManager.Factory.create(); LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() { @Oviewride public void onSuccess(LoginResult loginResult) { GraphRequest request = GraphRequest.newMeRequest( loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() { @Oviewride public void onCompleted(JSONObject object, GraphResponse response) { String email = object.optString("email"); String uid = object.optString("id"); loginPresenter.loginBySocial(email, uid); } }); Bundle pairameters = new Bundle(); pairameters.putString("fields", "email"); request.setPairameters(pairameters); request.executeAsync(); } @Oviewride public void onCancel() { //your code } @Oviewride public void onError(FacebookException exception) { //your code } }); } FacebookSdk.sdkInitialize(getActivity().getApplicationContext()); CallbackManager callbackManager = CallbackManager.Factory.create(); LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() { @Oviewride public void onSuccess(LoginResult loginResult) { GraphRequest request = GraphRequest.newMeRequest( loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() { @Oviewride public void onCompleted(JSONObject object, GraphResponse response) { String email = object.optString("email"); String uid = object.optString("id"); loginPresenter.loginBySocial(email, uid); } }); Bundle pairameters = new Bundle(); pairameters.putString("fields", "email"); request.setPairameters(pairameters); request.executeAsync(); } @Oviewride public void onCancel() { //your code } @Oviewride public void onError(FacebookException exception) { //your code } }); }); FacebookSdk.sdkInitialize(getActivity().getApplicationContext()); CallbackManager callbackManager = CallbackManager.Factory.create(); LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() { @Oviewride public void onSuccess(LoginResult loginResult) { GraphRequest request = GraphRequest.newMeRequest( loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() { @Oviewride public void onCompleted(JSONObject object, GraphResponse response) { String email = object.optString("email"); String uid = object.optString("id"); loginPresenter.loginBySocial(email, uid); } }); Bundle pairameters = new Bundle(); pairameters.putString("fields", "email"); request.setPairameters(pairameters); request.executeAsync(); } @Oviewride public void onCancel() { //your code } @Oviewride public void onError(FacebookException exception) { //your code } }); } FacebookSdk.sdkInitialize(getActivity().getApplicationContext()); CallbackManager callbackManager = CallbackManager.Factory.create(); LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() { @Oviewride public void onSuccess(LoginResult loginResult) { GraphRequest request = GraphRequest.newMeRequest( loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() { @Oviewride public void onCompleted(JSONObject object, GraphResponse response) { String email = object.optString("email"); String uid = object.optString("id"); loginPresenter.loginBySocial(email, uid); } }); Bundle pairameters = new Bundle(); pairameters.putString("fields", "email"); request.setPairameters(pairameters); request.executeAsync(); } @Oviewride public void onCancel() { //your code } @Oviewride public void onError(FacebookException exception) { //your code } }); } FacebookSdk.sdkInitialize(getActivity().getApplicationContext()); CallbackManager callbackManager = CallbackManager.Factory.create(); LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() { @Oviewride public void onSuccess(LoginResult loginResult) { GraphRequest request = GraphRequest.newMeRequest( loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() { @Oviewride public void onCompleted(JSONObject object, GraphResponse response) { String email = object.optString("email"); String uid = object.optString("id"); loginPresenter.loginBySocial(email, uid); } }); Bundle pairameters = new Bundle(); pairameters.putString("fields", "email"); request.setPairameters(pairameters); request.executeAsync(); } @Oviewride public void onCancel() { //your code } @Oviewride public void onError(FacebookException exception) { //your code } }); } FacebookSdk.sdkInitialize(getActivity().getApplicationContext()); CallbackManager callbackManager = CallbackManager.Factory.create(); LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() { @Oviewride public void onSuccess(LoginResult loginResult) { GraphRequest request = GraphRequest.newMeRequest( loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() { @Oviewride public void onCompleted(JSONObject object, GraphResponse response) { String email = object.optString("email"); String uid = object.optString("id"); loginPresenter.loginBySocial(email, uid); } }); Bundle pairameters = new Bundle(); pairameters.putString("fields", "email"); request.setPairameters(pairameters); request.executeAsync(); } @Oviewride public void onCancel() { //your code } @Oviewride public void onError(FacebookException exception) { //your code } }); 

    Encontrei uma solução: e funciona

     LoginFragment loginFragment = new LoginFragment() { @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = super.onCreateView(inflater, container, savedInstanceState); setReadPermissions(Arrays.asList("email")); return v; } }; } LoginFragment loginFragment = new LoginFragment() { @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = super.onCreateView(inflater, container, savedInstanceState); setReadPermissions(Arrays.asList("email")); return v; } }; 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.