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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:35:22+00:00 2026-06-05T19:35:22+00:00

I followed this tutorial to implement facebook into my application. All I want is

  • 0

I followed this tutorial to implement facebook into my application. All I want is to post a text on the user’s wall. I imported all the necessary files like RyanM said here.

Problem: when I do not provide an app id, facebook starts loading, then says an error occurred. Then I click OKAY in the top-right corner and facebook loads. Why?

There is another button for posting on wall. I do not want any buttons for this, where should I put the postOnWall("Testing from Android"); line? I want the post to appear on the users wall right after they log in.

When I provide my app id, facebook starts loading then exits. Why?

PostActivity:

package com.bfarago.af2;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;

public class PostActivity extends FacebookActivity {
    /** Called when the activity is first created. */
    private TextView txtUserName;
    private ProgressBar pbLogin;
    private Button btnLogin;
    private Button btnWall;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        txtUserName = (TextView) findViewById(R.id.textFacebook);
        pbLogin = (ProgressBar) findViewById(R.id.progressLogin);
        btnLogin = (Button) findViewById(R.id.buttonLogin);
        btnWall = (Button) findViewById(R.id.buttonWall);

        btnLogin.setOnClickListener(listener);
        btnWall.setOnClickListener(listener1);
    }

    OnClickListener listener = new OnClickListener(){
        @Override
        public void onClick(View v) {
            // pbLogin.setVisibility(ProgressBar.VISIBLE);
            setConnection();
            getID(txtUserName, pbLogin);
            postOnWall("Testing from Android");
        }
    };

    OnClickListener listener1 = new OnClickListener(){
        @Override
        public void onClick(View v) {
        // postOnWall("Testing from Android");
        }
    };
}

FacebookActivity:

package com.bfarago.af2;

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.view.View;
import android.widget.Button;
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 abstract class FacebookActivity extends Activity {
    public static final String TAG = "FACEBOOK";
    private Facebook mFacebook;
    public static final String APP_ID = "394196520626466"; //the API Key for your Facebook APPs
    private AsyncFacebookRunner mAsyncRunner;
    private static final String[] PERMS = new String[] { "publish_stream" };
    private SharedPreferences sharedPrefs;
    private Context mContext;

    private TextView username;
    private ProgressBar pb;

    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);

                            final String id = json.getString("id");
                            final String name = json.getString("name");
                            FacebookActivity.this.runOnUiThread(new Runnable() {
                                    public void run() {
                                            username.setText("Welcome: " + name+"\n ID: "+id);
                                            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);
    }

    public void postOnWall(String msg) {
        Log.d("Tests graph API %%%%%$$$$%%%", msg);
         try {
                String response = mFacebook.request("me");
                Bundle parameters = new Bundle();
                parameters.putString("message", msg);
                parameters.putString("description", "test test test");
                response = mFacebook.request("me/feed", parameters, 
                        "POST");
                Log.d("Tests", "got response: " + response);
                if (response == null || response.equals("") || 
                        response.equals("false")) {
                   Log.v("Error", "Blank response");
                }
         } catch(Exception e) {
             e.printStackTrace();
         }
    }

}

What I want:

enter image description 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-05T19:35:23+00:00Added an answer on June 5, 2026 at 7:35 pm

    Here’s what happens with your code:

    User clicks any button which calls the OnClickListener.onClick method.
    This method calls the setConnection method of the activity which constructs the facebook objects and return.
    Then the getID method is invoked which checks if the user is authorized or not.

    If the user is authorized you make an asynchronous request for /me, and then the method returns which immediately calls postOnWall.
    The problem is that the request to /me/feed is sent before the asynchronous request returns with the data.

    If the user is not authorized then you call mFacebook.authorize, and here in the onComplete method you again make an asynchronous request for /me but don’t wait for it to complete before calling postOnWall.

    In both cases you need to wait for the asynchronous request to complete, something like:

    OnClickListener listener = new OnClickListener(){
        @Override
        public void onClick(View v) {
            // pbLogin.setVisibility(ProgressBar.VISIBLE);
            setConnection();
            getID(txtUserName, pbLogin);
        }
    };
    

    And (notice that I move the postOnWall invocation to the onComplete here):

    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);
    
                        final String id = json.getString("id");
                        final String name = json.getString("name");
                        FacebookActivity.this.runOnUiThread(new Runnable() {
                                public void run() {
                                        username.setText("Welcome: " + name+"\n ID: "+id);
                                        pb.setVisibility(ProgressBar.GONE);
    
                                }
                        });
                        postOnWall("Testing from Android");
                } catch (JSONException e) {
                        Log.d(TAG, "JSONException: " + e.getMessage());
                } catch (FacebookError e) {
                        Log.d(TAG, "FacebookError: " + e.getMessage());
                }
        }
    
        ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I followed this tutorial here: http://www.dannyherran.com/2011/02/facebook-php-sdk-and-codeigniter-for-basic-user-authentication/ It works great but when I enable CSRF
I've followed this tutorial but when I try to run the application I get
I followed this tutorial : http://blog.mugunthkumar.com/coding/iphone-tutorial-how-to-send-in-app-sms/ and I got the alert 'Text messaging is
I have followed this great tutorial and I finally managed to implement a 3
To implement database access in my application I followed Lars Vogel tutorial , but
To implement database access in my application I followed Lars Vogel tutorial , but
I have followed this tutorial for building my chat application. When I try to
I have followed this tutorial which uses jQuery UI to generate Facebook tokens like:
I followed this tutorial to setup auto-completion functions for figlet / toilet . #
I followed this tutorial to connect a digit.tree to a store.JsonRest and everything works

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.