Friday, April 8, 2016

How to Facebook or Google or G+ login in android and fetch user profile

While working on an idea of my new app I had this requirement of allowing users to use there Facebook or Google account. Facebook auth was easy and without any difficulty I could get the users profile info etc. But Google Auth + GPlus data fetching was a pain as they both involve different api strategy and I started working on it but I was stuck for days ! Unfortunately any example I found in internet for Google Auth + GPlus data fetching is either obsolete or doesnt work ! Even googles developer page is also not updated with correct functions.
It was quite impossible to get both data in one api call ! I then cracked it with the below minor changes to my existing code. Hope it helps to any android enthusiatic.

It was quite impossible to get both data in one api call ! I then cracked it with the below minor changes to my existing code. Hope it helps to any android enthusiatic.
Fetch G+ data with GoogleSignin
A slight modification to GoogleSignInClient can fetchus both Google account + GPlus data
Create the GoogleSignInOptions as below
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestEmail()
                .requestScopes(new Scope(Scopes.PLUS_LOGIN))
                .build();
Create the GoogleApiClient as below
m_GoogleApiClient = new GoogleApiClient.Builder(m_activity)
                .enableAutoManage(m_activity, this)
                .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                .addApi(Plus.API)
                .build();
public void fetchConnectedProfileInfo()
{
    Log.d(TAG, "fetchConnectedProfileInfo");
    if (m_GoogleApiClient.hasConnectedApi(Plus.API)) {
        Plus.PeopleApi.load(m_GoogleApiClient, "me").setResultCallback(this);
    }
}
Call fetchConnectedProfileInfo() from MainActivity.java onActivityResult()

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    getCallbackManager().onActivityResult(requestCode, resultCode, data);
    if (requestCode == RC_SIGN_IN) {
        GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
        Log.d(TAG, "handleSignInResult:" + result.isSuccess());
        if (result.isSuccess()) {
            GoogleSignInAccount acct = result.getSignInAccount();
            Bundle googleData = m_gAuthProcessor.getGoogleAccData(acct);
           fetchConnectedProfileInfo();
        } else {
            notifyus("googleAuthFailed", null);
            // Signed out, show unauthentic
        }
    }
}
Code is available here https://github.com/sandipsahoo2k2/social-login

Sunday, March 27, 2016

creating a mobile site with users status | realtime apps

we would be using digital ocean for this

https://www.digitalocean.com/community/articles/initial-server-setup-with-ubuntu-12-04
https://www.digitalocean.com/community/articles/how-to-set-up-a-host-name-with-digitalocean
https://www.digitalocean.com/community/articles/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu

https://www.digitalocean.com/community/articles/how-to-set-up-multiple-wordpress-sites-on-a-single-ubuntu-vps

install npm and nodejs in digital ocean
create a soft link for nodejs

ln -s  /usr/bin/nodejs  /usr/bin/node other wise you wont be able to install redis/hiredis with node module.
-I/usr/include/x86_64-linux-gnu if make fails for redis compilation

Great Tutorial
http://www.smartjava.org/content/create-simpe-restful-service-vertx-20-rxjava-and-mongodb
http://www.javaworld.com/article/2078838/mobile-java/open-source-java-projects-vert-x.html?null


android examples
-----------------
http://javapapers.com/android/android-chat-with-google-gcm-xmpp/
http://www.androidhive.info/2016/02/android-push-notifications-using-gcm-php-mysql-realtime-chat-app-part-3/
http://code.tutsplus.com/tutorials/quick-tip-add-facebook-login-to-your-android-app--cms-23837