Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6318633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:39:41+00:00 2026-05-24T15:39:41+00:00

Here is my code realising the connection. import java.io.FileNotFoundException; import java.io.IOException; import java.net.MalformedURLException; import

  • 0

Here is my code realising the connection.

import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;

import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.facebook.android.AsyncFacebookRunner;
import com.facebook.android.AsyncFacebookRunner.RequestListener;
import com.facebook.android.DialogError;
import com.facebook.android.Facebook;
import com.facebook.android.Facebook.DialogListener;
import com.facebook.android.FacebookError;
import com.facebook.android.Util;

public class FacebookConnect extends Activity{

    public static final String TAG = "FACEBOOK";
    private Facebook mFacebook;
    public static final String APP_ID = "XXX";
    private AsyncFacebookRunner mAsyncRunner;
    private static final String[] PERMS = new String[] { "read_stream" };
        private SharedPreferences sharedPrefs;
        private Context mContext; 

        private TextView username;
        private ProgressBar pb;
        String fbId, fbName, fbEmail;

        public void setConnection() {
                mContext = this;
                mFacebook = new Facebook(APP_ID);
                mAsyncRunner = new AsyncFacebookRunner(mFacebook);
        }

        public void getID(TextView txtUserName, ProgressBar progbar) {
                username = txtUserName;
                pb = progbar;
                if (isSession()) {
                        Log.d(TAG, "sessionValid");
                        mAsyncRunner.request("me", new IDRequestListener());
                } else {
                    // no logged in, so relogin
                    Log.d(TAG, "sessionNOTValid, relogin");
                        mFacebook.authorize(this, PERMS, new LoginDialogListener());
                }
        }

        public boolean isSession() {
                sharedPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
                String access_token = sharedPrefs.getString("access_token", "x");
            Long expires = sharedPrefs.getLong("access_expires", -1);
                Log.d(TAG, access_token);

                if (access_token != null && expires != -1) {
                        mFacebook.setAccessToken(access_token);
                        mFacebook.setAccessExpires(expires);
                }
                return mFacebook.isSessionValid();
        }

        private class LoginDialogListener implements DialogListener {

                @Override
                public void onComplete(Bundle values) {
                        Log.d(TAG, "LoginONComplete");
                    String token = mFacebook.getAccessToken();
                    long token_expires = mFacebook.getAccessExpires();
                    Log.d(TAG, "AccessToken: " + token);
                    Log.d(TAG, "AccessExpires: " + token_expires);
                    sharedPrefs = PreferenceManager
                                    .getDefaultSharedPreferences(mContext);
                    sharedPrefs.edit().putLong("access_expires", token_expires).commit();
                    sharedPrefs.edit().putString("access_token", token).commit();
                    mAsyncRunner.request("me", new IDRequestListener());
                }

                @Override
                public void onFacebookError(FacebookError e) {
                        Log.d(TAG, "FacebookError: " + e.getMessage());
                }

                @Override
                public void onError(DialogError e) {
                        Log.d(TAG, "Error: " + e.getMessage());
                }

                @Override
                public void onCancel() {
                        Log.d(TAG, "OnCancel");
                }
        }

        private class IDRequestListener implements RequestListener {

                @Override
                public void onComplete(String response, Object state) {
                        try {
                                Log.d(TAG, "IDRequestONComplete");
                            Log.d(TAG, "Response: " + response.toString());
                                JSONObject json = Util.parseJson(response);
                                fbId = json.getString("id");
                                fbName = json.getString("name");
                                //fbEmail = json.getString("email");

                                FacebookConnect.this.runOnUiThread(new Runnable() {
                                    public void run() {
                                    username.setText("Welcome: " + name + "\n ID: " + fbId);
                                pb.setVisibility(ProgressBar.GONE);
                                    }
                            });
                        } catch (JSONException e) {
                                Log.d(TAG, "JSONException: " + e.getMessage());
                    } catch (FacebookError e) {
                            Log.d(TAG, "FacebookError: " + e.getMessage());
                        }
                }

                @Override
                public void onIOException(IOException e, Object state) {
                        Log.d(TAG, "IOException: " + e.getMessage());
                }

                @Override
                public void onFileNotFoundException(FileNotFoundException e,
                                Object state) {
                        Log.d(TAG, "FileNotFoundException: " + e.getMessage());
                }

                @Override
                public void onMalformedURLException(MalformedURLException e,
                                Object state) {
                        Log.d(TAG, "MalformedURLException: " + e.getMessage());
                }

                @Override
                public void onFacebookError(FacebookError e, Object state) {
                        Log.d(TAG, "FacebookError: " + e.getMessage());
                }

        }

        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
                mFacebook.authorizeCallback(requestCode, resultCode, data);
        }
}

As a response I get a JSON. Example:

08-15 14:22:42.160: DEBUG/FACEBOOK(1258): Response: {"id":"3159628280","name":"Peter Black","first_name":"Peter","last_name":"Black","link":"http:\/\/www.facebook.com\/Peter.Black","username":"Peter.Black","gender":"male","timezone":3,"locale":"bg_BG","verified":true,"updated_time":"2011-08-14T08:42:59+0000"}

My question is how can I get the user’s email (the email with which he logs into Facebook)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T15:39:42+00:00Added an answer on May 24, 2026 at 3:39 pm

    You need the email permission to read the users email adress.
    That will add a email tag in your json-response from [uid] or me requests.

    email

    Provides access to the user’s primary email address in the email
    property. Do not spam users. Your use of email must comply both with
    Facebook policies and with the CAN-SPAM Act.

    Source: Permissions

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please see the code here: http://pastie.org/1092106 When I call the method createPost on Blog,
I have here java code accessing mySQL database. It checks if table exists. The
Edit: The code here still has some bugs in it, and it could do
See here: http://code.google.com/p/ie7-js/ Does anyone have any experience or remarks about this javascript? Is
I have this code here: var infiltrationResult; while(thisOption) { var trNode = document.createElement('tr'); var
We have some old C code here that's built with nmake. Is there an
I am using pseudo-code here, but this is in JavaScript. With the most efficient
I have a piece of code here that i really could use some help
I've got this code here: SqlCommand CodeStatus = new SqlCommand(SQL, DB); DB.Open(); Reader =
I am compiling a legacy C code here and there is a lot of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.