how to set scope in socialauth to get email only from google+ (for android app)

440 views
Skip to first unread message

Kuria Ndungu

unread,
Jan 26, 2014, 4:44:01 PM1/26/14
to socialau...@googlegroups.com
Hi, I'm a newbie to this wonderful library.
I have a Google plus Client ID and Secret for my app but i'm having a small issue. I'm interested in getting only the users email as i use it to send weekly spend details (its a finance app) .
I'm able to query google plus successfully however the issue is that apart from email , contacts, photos, circles etc are requested.
Could someone kindly show me how to limit the scope to get email only?

I have tried using Google only instead of Google plus but I keep getting a page advising that i switch to use Google+

Have also tried adding a parameter to the oauth_consumer.properties file but its not working.
#Google Plus
www.google.com.consumer_key =xxxxxxxx.apps.googleusercontent.com
www.google.com.consumer_secret = r4lxxxxxxxxOo

Any help will be much appreciated.

Kuria Ndungu

unread,
Jan 26, 2014, 4:52:37 PM1/26/14
to socialau...@googlegroups.com
I managed to get some success by changing the last line from www.google.com to googleapis.com. The only thing remaining now is to get rid of the extra dialog that pops up asking the user to again choose either "Profile","Friends" etc.

#Google Plus
googleapis.com.consumer_key=xxxxxxx.apps.googleusercontent.com
googleapis.com.consumer_secret=exxxxxxxxxxx

Kuria Ndungu

unread,
Jan 26, 2014, 4:58:47 PM1/26/14
to socialau...@googlegroups.com


On Monday, January 27, 2014 12:44:01 AM UTC+3, Kuria Ndungu wrote:
 
Hi, I'm a newbie to this wonderful library. (it is easily the most powerful , easy to use library out there - great job by the team!)

Tarun Nagpal

unread,
Jan 27, 2014, 11:39:16 AM1/27/14
to socialau...@googlegroups.com

Create Permission object

Permission perm = Permission.AUTHENTICATE_ONLY;

And use the following function of socialauth manager

getAuthenticationUrl(final String id, final String successUrl, final Permission perm)


Regards
Tarun
Message has been deleted

Kuria Ndungu

unread,
Jan 28, 2014, 5:18:47 PM1/28/14
to socialau...@googlegroups.com
Thanks Tarun for the reply.
I however was able to resolve the issue completely using the code below. I paste it in the hopes that it could help someone one day.
 (it took me 6 days of searching everything about Oauth along with trying all the libraries & examples i could find...scribe,signpost etc. but SocialAuth was the best and most straight forward to use. A big UP to Tarun and the team that created this fantastic Library)

//so heres the code.

     // I have an activity which has a layout with 2 imagevies. One for facebook and other for googleplus. On the onclick even I call this code below and pass a parameter denoting which one was clicked.

    private void runSocialOauthStuff(String strProvider) {
        AdapterSocialAuth = new SocialAuthAdapter(new ResponseListener()); //create a new instance of the adapter. I've already initialized it in code above so at this point I'm just creating an instance
        

           try {

            if(strProvider.contains("google")) {
                AdapterSocialAuth.addConfig(SocialAuthAdapter.Provider.GOOGLEPLUS,
                                                   "xxxxxxxx.apps.googleusercontent.com", //put the client key here
                                                   "xxxxxx", // client secret here
                                                   "https://www.googleapis.com/auth/userinfo.profile,https://www.googleapis.com/auth/userinfo.email"); //this is the google permissions. here i ask only for email addr.
                AdapterSocialAuth.addCallBack(SocialAuthAdapter.Provider.GOOGLEPLUS,"https://UrlYouGotWhenYouSignedUP/svc/auth/oauth2callback"); // this callback depends on the values you got when you signed up on the google console
                AdapterSocialAuth.authorize(Activity_SignUp.this, SocialAuthAdapter.Provider.GOOGLEPLUS); //this step does the work and calls the webview for users to log in. the response is sent to the response listener shown below

            } else { //here i have also some code for facebook. 
                if(strProvider.contains("facebook")) {
                    AdapterSocialAuth.addConfig(SocialAuthAdapter.Provider.FACEBOOK,
                                                       "xxxxxxxxxx", //client key
                                                       "xxxxxxxxxxxxxxxxxxxx", //client secret
                                                       "email"); //permissions
                    AdapterSocialAuth.addCallBack(SocialAuthAdapter.Provider.FACEBOOK,"https://theUrlYouGotWhenSigningUP/svc/auth/facebook"); //enter the callback url you get when signing up.
                    AdapterSocialAuth.authorize(Activity_SignUp.this, SocialAuthAdapter.Provider.FACEBOOK);

                };

            }
        } catch (Exception e) {
            Toast.makeText(Activity_SignUp.this,"Error Occured " + e.getMessage(),Toast.LENGTH_LONG).show();
            e.printStackTrace();
        }


    }
//the response listener gets the results from the above code. Mine is simple because I'm only interested in email. You could get any of the other profile details that user has authorized.
    private final class ResponseListener implements DialogListener {


        @Override
        public void onComplete(Bundle values) {
           String strUserEmail;
           Profile profileMap =  AdapterSocialAuth.getUserProfile();

           strUserEmail=profileMap.getEmail();
            if(strUserEmail!=null && strUserEmail.trim().length()>0){
                db = DatabaseRoutines.getInstance(Activity_SignUp.this); // I initialize my database instance
                db.setUserEmail(strUserEmail);  // here i save to the db. 
                Toast.makeText(Activity_SignUp.this,"The Email " + strUserEmail + " Saved Successfully.",Toast.LENGTH_LONG).show(); // message to the user showing the actual email saved
                GotoMainPage(); // this closes the current activity using "finish()" and opens the main activity.
            } else {
                Toast.makeText(Activity_SignUp.this,"Email Address could not be acquired. Please try again.",Toast.LENGTH_LONG).show();
            }


        }
Reply all
Reply to author
Forward
0 new messages