antonkrasov / AndroidSocialNetworks

Library for easy work with Facebook, Twitter, LinkedIn and Google on Android
1.04k stars 260 forks source link

Get user's email from Facebook & Google+ #29

Open PoCk3T opened 10 years ago

PoCk3T commented 10 years ago

Hello everyone,

Again, as I was already telling Anton by email, congrats for the work done here, it's brilliant and really make our life easier for social networking implementation.

I'm writing here because I was wondering how to retrieve user's email. I need it in the "login" feature of Social Networks, and only for Google+ & Facebook, and I was quite surprised it was not possible to access user's email from SocialPerson.email yet because I know Facebook Android SDK & Google+ Android API allow this :smiley:

So based on Anton suggestion, here's my issue ticket regarding this.

Also, here's how that could be done & implemented in Android Social Networks : -- For Facebook

Line 166 of "FacebookSocialPerson.java" (in the "impl" folder of Social Networks) '''request.executeAsync();'''

Just before we could add '''Bundle params = request.getParameters(); request.putString("fields", "email,name,<OTHER NECESSARY ?>"); request.setParameters(params);'''

Facebook's default approved item for an application to connect to FB's APIs include email, by default, again, so might be good for Facebook scopes already.

-- For Google+ Line 100 of "GooglePlusSocialNetwork.java" (in the "impl" folder of Social Networks) '''Person person = mPlusClient.getCurrentPerson();'''

We could simply add after that : socialPerson.email = mPlusClient.getAccountName(); For me, "getAccountName" possibly returns the email of the user (not always the case, but worth try it :dancers: )

Maybe the scopes need to be extended compared to what Social Networks is asking. Here is what I used to ask as 'scopes' for Google+ sign in :+1:

'''mPlusClient = new PlusClient.Builder(mContext, this, this).setScopes(Plus.SCOPE_PLUS_LOGIN.en(), Plus.SCOPE_PLUS_PROFILE.en()).build();'''

What do you think guys ? :smile:

gorbin commented 10 years ago

Yes you right, we can get emails only from g+ and facebook. You can try in my extension of this lib: https://github.com/gorbin/ASNE Soon I will pull these changes to this lib

I suggest just normolize SocialPerson and add DetailedPersons: Social person like: https://github.com/gorbin/ASNE/blob/master/library/src/main/java/com/androidsocialnetworks/lib/persons/SocialPerson.java and detailed like, for more detailed profile if somebody need, for example birthdays or company name: https://github.com/gorbin/ASNE/blob/master/library/src/main/java/com/androidsocialnetworks/lib/persons/FacebookPerson.java

gorbin commented 10 years ago

add detail and Social person as I wrote...

add email in SocialPerson in pull