1

I created a small application which logs in to Facebook and then I can post the text on wall. It worked well at first. But the next day, the application gets Facebook onerror.

public class fblogin extends Activity implements OnClickListener {

    String API_ID;
    Facebook fb;
    TextView fronttext;
    ImageView pic;
    Button postbutton,loginfb; 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.loginscreen);

        API_ID = getString(R.string.API_ID);
        fb= new Facebook(API_ID);
        pic=(ImageView) findViewById(R.id.picture_pic);
        fronttext=(TextView)findViewById(R.id.fronttext);
        postbutton= (Button)findViewById(R.id.post);
        loginfb=(Button)findViewById(R.id.login);

        loginfb.setOnClickListener(this);
        updateButtonImage();
    }

    public void updateButtonImage()
    {
        if(fb.isSessionValid())
        {   
            postbutton.setVisibility(Button.VISIBLE);
            loginfb.setText("Logout");
            fronttext.setText("WelCome ");
            pic.setVisibility(ImageView.VISIBLE);
            Toast.makeText(getApplicationContext(), "You are log In ",Toast.LENGTH_LONG);


            JSONObject obj=null;
            URL img_url=null;

            try {
                String jsonUser = fb.request("me");
                obj=Util.parseJson(jsonUser);
                String id = obj.optString("id");
                String name=obj.optString("name");
                fronttext.setText("WelCome "+ name);
                img_url =new URL("http://graph.facebook.com/"+id+"/picture?type=small");
                Bitmap bmp=BitmapFactory.decodeStream(img_url.openConnection().getInputStream()); 
                pic.setImageBitmap(bmp);

            } catch (FacebookError e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }



        }
        else
        {
            postbutton.setVisibility(Button.INVISIBLE);
            loginfb.setText("Login");
            fronttext.setText("To get Started , Login Using Facebook");
            pic.setVisibility(ImageView.INVISIBLE);
            Toast.makeText(getApplicationContext(), "You are log Out ",Toast.LENGTH_LONG);
        }

    }

    public void postbuttonClicks(View v)
    {
        switch(v.getId()){
        case R.id.post:
            //post
            fb.dialog(fblogin.this,"feed",new DialogListener() {

                @Override
                public void onFacebookError(FacebookError e) {
                    // TODO Auto-generated method stub
                    Toast.makeText(fblogin.this, "facebook Error....", Toast.LENGTH_LONG).show();
                }

                @Override
                public void onError(DialogError e) {
                    // TODO Auto-generated method stub
                    Toast.makeText(fblogin.this, "Error On Page.....", Toast.LENGTH_LONG).show();
                }

                @Override
                public void onComplete(Bundle values) {
                    Toast.makeText(fblogin.this, "Sucessfully Post on wall...", Toast.LENGTH_LONG).show();

                }

                @Override
                public void onCancel() {
                    Toast.makeText(fblogin.this, "Cancel The Activity....", Toast.LENGTH_LONG).show();

                }
            });

            break;

        }


    }
    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub
        if(fb.isSessionValid()){
            //log out

        try {
            fb.logout(getApplicationContext());
            updateButtonImage();
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        }

        else{
            //login
               fb.authorize(fblogin.this,new DialogListener() {

                   @Override
                    public void onComplete(Bundle values) {

                        updateButtonImage();
                    }
                   @Override
                public void onFacebookError(FacebookError e) {
                       updateButtonImage();
                    Toast.makeText(fblogin.this, "facebookError", Toast.LENGTH_LONG).show();
                }

                @Override
                public void onError(DialogError e) {

                    Toast.makeText(fblogin.this, "facebookon...Error", Toast.LENGTH_LONG).show();
                }



                @Override
                public void onCancel() {
                    // TODO Auto-generated method stub
                    Toast.makeText(fblogin.this, "facebookCancel", Toast.LENGTH_LONG).show();
                }
            });

        }
    }  
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        super.onActivityResult(requestCode, resultCode, data);
         fb.authorizeCallback(requestCode, resultCode, data);

    }
}

Then I created onActivityResult method and error gets resolved and I can login. But today once again I got that error. What do I do to solve it? Is there a problem in my program? Or a session problem?

Minp
  • 98
  • 1
  • 1
  • 13
  • What error? Post your logcat. – Siddharth Lele Oct 13 '12 at 04:44
  • 10-13 10:18:51.753: ERROR/ActivityThread(808): Failed to find provider info for com.facebook.katana.provider.AttributionIdProvider – Minp Oct 13 '12 at 04:52
  • You seem to have the wrong Hash Key in your App Dashboard (Facebook). – Siddharth Lele Oct 13 '12 at 04:55
  • output shows onclick dialog "facebookon..error" toast message.. – Minp Oct 13 '12 at 04:57
  • but i had run this program successfully last 2 days.. – Minp Oct 13 '12 at 04:58
  • Did you change your workstation in between these days? – Siddharth Lele Oct 13 '12 at 04:59
  • no...i got this error yesterday but when i write Onactivityresult method it login and run proper... – Minp Oct 13 '12 at 05:01
  • See if the solution from this answer of mine works for you: http://stackoverflow.com/a/10516629/450534. Look at the instructions in the second comment. Check the logcat output and see if it reports an error. – Siddharth Lele Oct 13 '12 at 05:08
  • okk i will change it...but not working..I have a doubt i don't see 3g icon on emulator...so is it that problem??? – Minp Oct 13 '12 at 05:15
  • As long as the computer you are running the emulator on has internet connectivity, you should be okay. Also, you might try to uninstall the app from the emulator and push a fresh copy again. And _but not working_ isn't very helpful. Post any new errors in you post. – Siddharth Lele Oct 13 '12 at 05:20
  • i think you sould check your network as well as your sessionID – Manoj Kumar Oct 13 '12 at 05:21
  • Run my program successfully after 3G icon shows..means internet permission cant get...Thanks to u for helping me.. – Minp Oct 13 '12 at 05:22
  • now i want to fetch my facebook feed wall..how can i fetch it..i use JSONUser to fetch my profile pic and name.. – Minp Oct 13 '12 at 05:23
  • hey help me how to fetch news feeds from facebook in android... – Minp Oct 13 '12 at 05:57

0 Answers0