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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:18:18+00:00 2026-05-27T21:18:18+00:00

I am using following code to post image on Facebook wall. it’s working fine.

  • 0

I am using following code to post image on Facebook wall.
it’s working fine.

Problem is –> if the device having Facebook Application i am not able to post image on wall.

–>The device does’t having Facebook App. it’s working without any problems.

please help me where is the problem.
this is the code i am using here.

public class ShareOnFacebook extends Activity  {

private static final String APP_ID = "269876589726953";
private static final String[] PERMISSIONS = new String[] {"publish_stream"};

private static final String TOKEN = "access_token";
private static final String EXPIRES = "expires_in";
private static final String KEY = "facebook-credentials";

      private Facebook facebook;
      private String messageToPost; 
      private Bitmap mBitmap;

      public boolean saveCredentials(Facebook facebook) {
           Editor editor = getApplicationContext().getSharedPreferences(KEY, Context.MODE_PRIVATE).edit();
                  editor.putString(TOKEN, facebook.getAccessToken());
                  editor.putLong(EXPIRES, facebook.getAccessExpires());
                    return editor.commit();
            }

    public boolean restoreCredentials(Facebook facebook) {
        SharedPreferences sharedPreferences = getApplicationContext().getSharedPreferences(KEY, Context.MODE_PRIVATE);
        facebook.setAccessToken(sharedPreferences.getString(TOKEN, null));
        facebook.setAccessExpires(sharedPreferences.getLong(EXPIRES, 0));
        return facebook.isSessionValid();
    }

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);  

    mBitmap = CropImage.getBitmapCrop();    

    facebook = new Facebook(APP_ID);
    restoreCredentials(facebook);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.share);

    String facebookMessage = getIntent().getStringExtra("facebookMessage");
    if (facebookMessage == null){
        facebookMessage = "Test wall post";
    }
    messageToPost = facebookMessage;
}

public void doNotShare(View button){
    finish();
}
public void share(View button){
    if (! facebook.isSessionValid()) {
        loginAndPostToWall();
    }
    else {
        postToWall(messageToPost);
    }
}

public void loginAndPostToWall(){
     facebook.authorize(this, PERMISSIONS, new LoginDialogListener());
}

public void postToWall(String message)  { 


    // posting image on FB wall
    byte[] data = null;

    Bitmap bi = mBitmap;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    data = baos.toByteArray();
    Bundle params = new Bundle();
    params.putString(Facebook.TOKEN, facebook.getAccessToken());        
    params.putString("method", "photos.upload");
    params.putByteArray("picture", data);
    AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
    mAsyncRunner.request(null, params, "POST", new PhotoUploadListener(), null);

    finish();   
}

public class PhotoUploadListener extends com.facebook.android.BaseRequestListener {

    public void onComplete(final String response, final Object state) {         
        //dialog.dismiss();
        //showToast("Image shared on your facebook wall!");          
    }
    public void onFacebookError(FacebookError error) {
       //dialog.dismiss();
       Toast.makeText(getApplicationContext(), "Facebook Error: " + error.getMessage(),Toast.LENGTH_LONG).show();
    }
}

class LoginDialogListener implements DialogListener {
    public void onComplete(Bundle values) {
        saveCredentials(facebook);
        if (messageToPost != null){
        postToWall(messageToPost);
    }
    }
    public void onFacebookError(FacebookError error) {
        showToast("Authentication with Facebook failed!");
        finish();
    }
    public void onError(DialogError error) {
        showToast("Authentication with Facebook failed!");
        finish();
    }
    public void onCancel() {
        showToast("Authentication with Facebook cancelled!");
        finish();
    }
}

private void showToast(String message){
    Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
}
}
  • 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-27T21:18:19+00:00Added an answer on May 27, 2026 at 9:18 pm

    Small Changes in the code (facebook package)

    Look into authorize function in facebook.java file. try to comment out the singlesignon and use startdialog() only.Hope it helps.

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

Sidebar

Related Questions

I am sharing title, image and description of post in Facebook using following code
I am using the following PHP code to post to my page wall. it
I am using following code to post on a user's wall. Bundle params =
Hi Im using the following code: http://vikaskanani.wordpress.com/2011/01/11/android-upload-image-or-file-using-http-post-multi-part/ To POST an image to a WCF
I am using the following code (from a blog post) to resize an image
Trying to post an image along with wall post was working fine for couple
I'm using the following code to post to the server which is then sent
I am successfully posting a form via ajax, using the following code; $.post( Page.do?source=ajax,
I have the following snippet of code (I'm using jQuery 1.4.2): $.post('/Ads/GetAdStatsRow/', { 'ad_id':
I am using the following code to upload an image to a web server

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.