kirti Hudda
kirti Hudda

Reputation: 304

Update status over Facebook by using SocialAuth with different activities

I am trying to update status by using Socialauth library,but in place of dialog box i want to update status by an activity. Its done with Dialog box, but I want to do with activity.

I have two activities - one activity contains the two button one is login and other is next button, as i click on login then it authenticate succesfully and on clicking next I come on next activity which contain a edittext and button. In edit text i type my message and on button click I call updateStatus() method of Social auth. But I am getting the response from server i.e error 403..

Here is my code

public class Social_MainActivity extends Activity {

  public static SocialAuthAdapter adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_social__main);
    Button login=(Button) findViewById(R.id.buttonLogin);

            adapter = new SocialAuthAdapter(new ResponseListener());
            login.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                           adapter.authorize(Social_MainActivity.this,Provider.FACEBOOK);

                }
            });



           next.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                Intent i=new Intent(Social_MainActivity.this,ProviderActivity.class);
                startActivity(i);
            }
        });


}



class ResponseListener implements DialogListener
{




    @Override
    public void onComplete(Bundle values) {
        // TODO Auto-generated method stub

        Toast.makeText(Social_MainActivity.this, "You are login", 1000).show();*/
    }

    @Override
    public void onError(SocialAuthError e) {
        // TODO Auto-generated method stub
         Log.d("ShareBar", e.getMessage());


    }

    @Override
    public void onCancel() {
        // TODO Auto-generated method stub
        Log.d("ShareBar", "Authentication Cancelled");

    }

    @Override
    public void onBack() {
        // TODO Auto-generated method stub

    }


    }
         }

ProvideActivity:

      public class ProviderActivity extends Activity{

SocialAuthAdapter adapter;
EditText ed;
Button b;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.provider_activity);
    ed=(EditText) findViewById(R.id.shareText);
    b=(Button) findViewById(R.id.updatebutton);
    b.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            adapter = Social_MainActivity.adapter;
            adapter.updateStatus(ed.getText.toString(),new MessageListener(),true); 
            Toast.makeText(ProviderActivity.this,"updated", 1000).show();

        }
    });
       }
     private final class MessageListener implements SocialAuthListener<Integer> {




    @Override
    public void onExecute(String provider, Integer t) {
        // TODO Auto-generated method stub
         Integer status = t;
           if (status.intValue() == 200 || status.intValue() == 201 ||status.intValue() == 204)
           Toast.makeText(Social_MainActivity.this, "Message posted",Toast.LENGTH_LONG).show();
           else
           Toast.makeText(Social_MainActivity.this, "Message not posted",Toast.LENGTH_LONG).show();
           Log.e("Execute", "I am onExecute");

    }

    @Override
    public void onError(SocialAuthError e) {
        // TODO Auto-generated method stub
          Log.e("Error", "I am onExecute Error");

    }
    }

Upvotes: 1

Views: 353

Answers (1)

kirti Hudda
kirti Hudda

Reputation: 304

It have been solved. Here is my code.I am using 3 classes. If anyone can suggest me better way then please . This code is updating over Facebook as well as twitter.

public class Social_MainActivity extends Activity {


  static MySocialAuthAdapter myadap;

 Context con;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_social__main);
    con=this;


    Button share=(Button) findViewById(R.id.button1);
    Button twiitter=(Button) findViewById(R.id.button_twitterLogin);
    Button login=(Button) findViewById(R.id.buttonLogin);

  myadap=new MySocialAuthAdapter();// MySocialAuthAdapter is user defined class

            login.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    myadap.MyAuthorize(con, Provider.FACEBOOK);

                }
            });
           twiitter.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                myadap.MyAuthorize(con, Provider.TWITTER);

            }
        });
          share.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

        Intent i=new Intent(Social_MainActivity.this,ProviderActivity.class);
                startActivity(i);
            }
        });
       }


}

Class MySocialAuthAdapter:-

    public class MySocialAuthAdapter  {

public static SocialAuthAdapter adapter;
public MySocialAuthAdapter()
{
    adapter = new SocialAuthAdapter(new ResponseListener()); 


}
public void  MyAuthorize(Context context,SocialAuthAdapter.Provider provider)
{

    adapter.authorize(context, provider);

}
public  void  MyUpdateStatus(String msg)
{
    adapter.updateStatus(msg, new MessageListener(), true);
    Log.e("Message","Your message hv been updated");

}
  class ResponseListener implements DialogListener
{

    @Override
    public void onComplete(Bundle values) {

    }

    @Override
    public void onError(SocialAuthError e) {
        // TODO Auto-generated method stub
         Log.d("ShareBar", e.getMessage());


    }

    @Override
    public void onCancel() {
        // TODO Auto-generated method stub
        Log.d("ShareBar", "Authentication Cancelled");

    }

    @Override
    public void onBack() {
        // TODO Auto-generated method stub

    }


    }

    private final class MessageListener implements SocialAuthListener<Integer> { 
    @Override
    public void onExecute(String provider, Integer t) {
        // TODO Auto-generated method stub
         Integer status = t;
           if (status.intValue() == 200 || status.intValue() == 201 ||status.intValue() == 204)

          Log.e("Execute", "I am onExecute");

    }

    @Override
    public void onError(SocialAuthError e) {
        // TODO Auto-generated method stub
          Log.e("Error", "I am onExecute Error");

    }
    }
   }
   }

class ProviderActivity:-

 public class ProviderActivity extends Activity{
MyApplication myApp;
MySocialAuthAdapter myadapter;
EditText ed;
Button b;
String msg;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.provider_activity);
    ed=(EditText) findViewById(R.id.shareText);
    b=(Button) findViewById(R.id.updatebutton);
    b.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            Social_MainActivity.myadap.MyUpdateStatus(  ed.getText().toString());

        }
    });


}

}

Upvotes: 1

Related Questions