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

  • SEARCH
  • Home
  • 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 8781861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:25:06+00:00 2026-06-13T20:25:06+00:00

So, here’s my login function: public void facebookLogin() { shareAppPreferences = new AppPreferences(getApplicationContext()); facebook

  • 0

So, here’s my login function:

  public void facebookLogin()
{

    shareAppPreferences = new AppPreferences(getApplicationContext());
     facebook = ((GlobalVars)getApplicationContext()).facebook;

     String access_token = shareAppPreferences.getAccessToken();
     long expires = shareAppPreferences.getAccessExpires();
     Log.d("MyTag","token:" +access_token);
     if(access_token != null) {
         facebook.setAccessToken(access_token);
     }
     if(expires != 0) {
         facebook.setAccessExpires(expires);
     }
     /*
      * Only call authorize if the access_token has expired.
      */
     if(!facebook.isSessionValid()) {
         Log.d("MyTag","In Authorize");
          facebook.authorize(this, new String[] {}, new DialogListener() {
              @Override
              public void onComplete(Bundle values) {
                //  new AccessKeyTask().execute("http://37.49.226.66/allaroundme/requests.php");
                  shareAppPreferences.saveAccessToken(facebook.getAccessToken());
                  Log.d("MyTag","face token: " +facebook.getAccessToken());
                  shareAppPreferences.saveAccessExpires(facebook.getAccessExpires());

              }

              @Override
              public void onFacebookError(FacebookError error) {}

              @Override
              public void onError(DialogError e) {}

              @Override
              public void onCancel() {}
          });
     }
     Intent intent = new Intent(this,MainActivity.class);
     Log.d("MyTag", "starting activity");
     startActivity(intent);

}

I don’t really understand why this code doesn’t work, I logged out facebook via the facebook app before trying to use that code. the onComplete() seems not to happen and the access token is always null. but after my first login, I don’t have to enter the info. Can anyone help me here?

  • 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-06-13T20:25:07+00:00Added an answer on June 13, 2026 at 8:25 pm

    Here’s code that worked for me:

        public void loginToFacebook(){
            facebook.authorize(CandyCount.this, new String[]{"publish_stream", "email"}, Facebook.FORCE_DIALOG_AUTH, new DialogListener() {
    
                public void onFacebookError(FacebookError e) {
                    Toast.makeText(getApplicationContext(), "onFacebookError", Toast.LENGTH_SHORT).show();
                }
    
                public void onError(DialogError e) {
                    Toast.makeText(getApplicationContext(), "onError", Toast.LENGTH_SHORT).show();
                }
    
                public void onComplete(Bundle values) {
    
                    Editor editor = sp.edit();
                    editor.putString("access_token", facebook.getAccessToken());
                    editor.putLong("access_expires", facebook.getAccessExpires());
                    editor.commit();
                    updateButtonStatus();
    
                    getName();
    
                }
    
                public void onCancel() {
                    // TODO Auto-generated method stub
    
                }
    
            });
        }
    

    And in the onCreate:

        sp = getPreferences(MODE_PRIVATE);
        access_token = sp.getString("access_token", null);
        expires = sp.getLong("access_expires", 0);
        getName = sp.getString("name", null);
    
        if (access_token != null){
            facebook.setAccessToken(access_token);
            fbName.setText("Hello, " + getName);
            updateButtonStatus();
        }
        if (expires != 0){
            facebook.setAccessExpires(expires);
    
        }
    

    In the updateButtonStatus method I change the image of the button and in the onClick of the button I either sign out or log in according to whether session is valid.

    Check out this link it’s pretty good in explaining the facebook sdk.

    You just obviously would need to alter the code to fit your specific needs. I hope this helps!

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

Sidebar

Related Questions

Here's my test function (c#, visual studio 2010): [TestMethod()] public void TestGetRelevantWeeks() { List<sbyte>
Here is my class: public class A{ private void doIt(int[] X, int[] Y){ //change
Here's the view: @if (stream.StreamSourceId == 1) { <img class=source src=@Url.Content(~/Public/assets/images/own3dlogo.png) alt= /> }
Here is the code in a function I'm trying to revise. This example works
Here is the Javascript I currently have <script type=text/javascript> $(function() { $('.slideshow').hover( function() {
Here's my problem I have this javascript if (exchRate != ) { function roundthecon()
Here's my function: static Map AddFormation(Map _map, Tile tile, int x, int y, int
Here is my javascript code for a cursor focus function to go to username
Here is the code I'm using inside my AsyncTask DefaultHttpClient httpClient = new DefaultHttpClient();
Here is my problem. Our tech. writer or customer service will often create new

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.