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 6832683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:53:18+00:00 2026-05-26T22:53:18+00:00

I have a problem with accessing the graph API through my android application that

  • 0

I have a problem with accessing the graph API through my android application that retrieves a user’s friends as JSONObject, extracts their names and displays them on the screen. It is supposed to be a simple and straightforward task but apparently it is not. When I run my application on Android Nexus I, I login to Facebook, then I am asked I click “Allow” button to grant permissions and I am redirected to a blank page. I am expect to see the name of my friends but it does not happen. Could some one assist me.

public class Login extends Activity 
{
    Facebook mFacebook = new Facebook("201509899926116");
    AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(mFacebook);
    String FILENAME = "AndroidSSO_data";
    private SharedPreferences mPrefs;
    View linearLayout;

    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        linearLayout = findViewById(R.id.main_layout);

         /* Get existing access_token if any */
        mPrefs = getPreferences(MODE_PRIVATE);
        String access_token = mPrefs.getString("access_token", null);
        long expires = mPrefs.getLong("access_expires", 0);

        if(access_token != null)
        {
            mFacebook.setAccessToken(access_token);
        }
        if(expires != 0)
        {
            mFacebook.setAccessExpires(expires);
        }

        /* Only call authorize if the access_token has expired. */
        if(!mFacebook.isSessionValid())
        {
            mFacebook.authorize(this, new String[] {"user_birthday","email",
                  "user_relationships","user_religion_politics","user_hometown",
                  "user_location","user_relationship_details","user_education_history",
                  "user_likes","user_interests", "user_activities"},
                  new DialogListener() 
            {

                @Override
                public void onComplete(Bundle values)
                {
                    SharedPreferences.Editor editor = mPrefs.edit();
                    editor.putString("access_token", mFacebook.getAccessToken());
                    editor.putLong("access_expires", mFacebook.getAccessExpires());
                    editor.commit();

                    /* access the graph API */
                    Log.d("Facebook-Example-Friends Request", "Started API request");
                    mAsyncRunner.request("me/friends", new FriendsRequestListener());
                    Log.d("Facebook-Example-Friends Request", "Finished API request");
                }

                @Override
                public void onFacebookError(FacebookError error) {}

                @Override
                public void onError(DialogError e) {}

                @Override
                public void onCancel() {}
            });
        }
    }

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

    public class FriendsRequestListener implements com.facebook.android.AsyncFacebookRunner.RequestListener 
    {
        /**
         * Called when the request to get friends has been completed.
         * Retrieve and parse and display the JSON stream.
         */
        public void onComplete(final String response)
        {
            try 
            {
                // process the response here: executed in background thread
                Log.d("Facebook-Example-Friends Request", "response.length(): " + response.length());
                Log.d("Facebook-Example-Friends Request", "Response: " + response);

                final JSONObject json = new JSONObject(response);
                JSONArray d = json.getJSONArray("data");
                int l = (d != null ? d.length() : 0);
                Log.d("Facebook-Example-Friends Request", "d.length(): " + l);

                for (int i=0; i<l; i++) 
                {
                    JSONObject o = d.getJSONObject(i);
                    String n = o.getString("name");
                    String id = o.getString("id");

                    TextView tv = new TextView(Login.this);
                    tv.setText(n);
                    ((LinearLayout) linearLayout).addView(tv);
                }               
            }
            catch (JSONException e)
            {
                Log.w("Facebook-Example", "JSON Error in response");
            }
        }
    }
}
  • 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-26T22:53:19+00:00Added an answer on May 26, 2026 at 10:53 pm

    I think i might’ve found the issue.. According to the documentation on onComplet;

         /**
         * Called when a request completes with the given response.
         * 
         * Executed by a background thread: do not update the UI in this method.
         */
    

    And you are trying to update your UI, so addViews don’t actually get reflected on the UI thread.. You should create a method in your activity that you can call from onComplete with runOnUIThread.. Something like this;

    runOnUiThread(new Runnable() {
                public void run() {
                    inserFacebookNames(facebookContactNames);
                }
            });
    

    Let me know if this actually fixes it.. I’m curious if that was the reason..

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

Sidebar

Related Questions

i have problem with libhid . i found that there 2 way 4 accessing
I am having a problem accessing the ViewData object through javascript. I have set
I have a strange problem when accessing android sqlite datbase. I have a line
I have a problem with accessing values in the session through pagemethods. The example
I have a problem accessing OpenAM SVN repository using Subclipse and was hoping that
I have a problem accessing JSON data. I'm new to JSON and jquery so
I am building my first ASP.Net MVC based app and have a problem accessing
I have problem in some JavaScript that I am writing where the Switch statement
I have a user complaining that my app is taking a lot of CPU
I'm quite new to JS and jQuery. I have a problem accessing the properties

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.