I am building an app that connects to a website to fetch data. A login screen is provided that gives the option of logging in using the site username and password or using social apps like facebook, twitter and google. The buttons for which are provided. I have downloaded socialauth library to use with the app. I followed https://code.google.com/p/socialauth-android/ for instructions on how to use the library. But the documentation is rather sketchy. Any help on how to use the library will be greatly appreciated. Thanks in advance. EDIT: What mainly I want to do is to provide the login facility of facebook, google and twitter to log into my app just like the feature provided on many web sites and apps. Thanks again.
I am putting here code..Hope it will help you.. Note: You need to put oath_consumer.properties in your assets folder as well as add socialauth library in your project.
public class ClientLogin extends Activity {
TextView facebookLogin,TwitterLogin,LinkedInLogin;
SocialAuthAdapter adapter;
Button logout;
Context context;
Profile profileMap;
String Email,password;
String provider_Name;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.client_login);
context=this;
facebookLogin=(TextView) findViewById(R.id.textView_LoginFacebook);
TwitterLogin=(TextView) findViewById(R.id.textView_LoginTwitter);
LinkedInLogin=(TextView) findViewById(R.id.textView_LoginLinkedin);
logout=(Button) findViewById(R.id.button_loginLogout);
adapter = new SocialAuthAdapter(new ResponseListener());
facebookLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
provider_Name="facebook";
adapter.authorize(context, Provider.FACEBOOK);
}
});
TwitterLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
provider_Name="twitter";
adapter.authorize(context, Provider.TWITTER);
}
});
LinkedInLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
provider_Name="linkedin";
adapter.authorize(context, Provider.LINKEDIN);
}
});
logout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stubadapter.
adapter.signOut(context, Provider.FACEBOOK.toString()) ;
adapter.signOut(context, Provider.LINKEDIN.toString()) ;
adapter.signOut(context, Provider.TWITTER.toString()) ;
Toast.makeText(context,"succesfully Logged out",1000).show();
}
});
}
private final class ResponseListener implements DialogListener
{
public void onComplete(Bundle values) {
// Log.d("ShareButton" , "Authentication Successful");
Toast.makeText(context,"succesfully Logged in",1000).show();
//code is to get email id of user...
profileMap = adapter.getUserProfile();
if (provider_Name.equalsIgnoreCase("facebook"))
{
//to get email_id of user..
Email=profileMap.getEmail();
}
else if( provider_Name.equalsIgnoreCase("twitter"))
{
//to get email of user
Email=profileMap.getEmail();
}
else if (provider_Name.equalsIgnoreCase("linkedin"))
{
Email=profileMap.getEmail();
}
}
}
}