Im creating an application to login in Google+ and get friends emails.
Im authenticating succesfully and get token back , but when i fetch friends list , the user class of any single friends has emails=null...
here is the code (After already signed in and get authenticator class):
// Generated libraries for Google APIs
using Google.Apis.Authentication.OAuth2;
using Google.Apis.Authentication.OAuth2.DotNetOpenAuth;
using Google.Apis.Services;
using Google.Apis.Util;
using Google.Apis.Plus.v1;
using Google.Apis.Plus.v1.Data;
// For OAuth2
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OAuth2;
//....code for authentication skipped ....
//...callback from json (authentication success)
PlusService ps = new PlusService(new BaseClientService.Initializer()
{
Authenticator = authenticator
});
PeopleFeed peopleFeed = ps.People.List("me", PeopleResource.CollectionEnum.Visible).Fetch();
//After that when i inspect peopleFeed[0].Emails <--- this is null..
any help?
The Google+ API only returns public information. So even if you are permitted to see a person's email address, it does not necessarily mean that the information is public and that it will be returned.
Furthermore, the documentation at https://developers.google.com/+/api/latest/people/list only guarantees that the list of people returned will contain the person's
id
displayName
image
url
and that to get other information about the person, you will need to do a people.get against that ID. But, again, note that you may still not get their email if that information isn't public.
You could also use the Contacts v3 API to get friend's email addresses. You can cross map this to Google+ contacts by looking at the gContact:website element for the contact that comes back in the XML response:
<gContact:website href='http://www.google.com/profiles/1234567890' rel='profile'/>
In that element's href attribute, 1234567890 is the person identifier that would match the id field of the relevant person resource from people.list of the Google+ API.
Note that the profile link is not guaranteed to come back for a contact entry. This occurs when the contact has not been linked to a Google+ profile.
My first guess would be that it's a rights management issue. I remember when I asked for my Google API key, I had to mention what information I want to get.
Could you check your API key settings in the Google Developer network and see if you need to enable it there?
Related
I have a scenario where I have to read a mail sent out by a X person with a specific subject, which i will be receiving on a daily basis.
Is there any JAVA Gmail APi provided by google to retrieve the recent mail that i have received.
And also is there a way to retrieve the mail for a given date?
Yes there's a Gmail API and it has a Java client library, you can check the Quickstart to get used to it.
Now, for retrieving a list of mails you will need to use the Users.messages: list endpoint ( There's also a Java example on how to use that endpoint). Answering your question about retrieving certain emails, you will need to use the q parameter and set the values there as if you would be searching an email in the gmail search bar. I will leave you an example that you can try using the Try this API:
List emails from certain user and date.
Notice
You will only get the email's IDs, for getting more info about an email, you will have to use the Users.messages: get endpoint.
I'm doing like this.
ListConnectionsResponse r = peopleService.people().connections()
.list("people/me")
.setPageSize(500)
// specify fields to be returned
.setRequestMaskIncludeField("person.names,person.emailAddresses")
.execute();
It returns a list of my connections with emails I have added myself. But not the information gathered from Google+ profiles. Is this possible to fetch also? I tried fetching the individual resourceName, but no email there.
Person p = peopleService.people().get("people/XXxxx").execute();
The Google People API actually does fetch the emails from Google+ profiles, but only the public e-mails. So if the e-mail shows up when you view their profile when not signed in, then it should show up in the response.
However, e-mails that are not public but are shared with your account (e-mails you can only see if you are signed in) are NOT visible through the Google People API for privacy reasons.
I have got accesstoken using oauth2.0. I am able to get the person name, gender, etc but I am not able to get the email address of the user.
Could any one please paste some sample code or any suggestions on how to get the email address from the google plus API?
You can retrieve a user's email address if they specifically authorize your application to see their email address.
Set your scopes to:
https://www.googleapis.com/auth/plus.login
https://www.googleapis.com/auth/userinfo.email
The JavaScript calls look like this:
gapi.client.load('oauth2', 'v2', function() {
gapi.client.oauth2.userinfo.get().execute(function(resp) {
// Shows user email
console.log(resp.email);
})
});
gapi.client.load('plus', 'v1', function() {
gapi.client.plus.people.get( {'userId' : 'me'} ).execute(function(resp) {
// Shows other profile information
console.log(resp);
})
});
More information https://developers.google.com/+.
Note that you do not need scopes for plus.me or userinfo.profile.
Exposing E-mail addresses of people who have not set it to be visible to 'Public' would obviously be a privacy issue, so that's not possible.
Exposing E-mail addresses of people who have set their E-mail address visibility to 'Public' is possible, but not yet there. It is currently an open issue
Edit: The issue is resolved now, so you can follow the steps in the other answer to get it.
I'm trying to get friends count via my account using Facebook API. Its working well.
But if i get friends count using one of my friendId, i'm getting the following exception
Tests in error: friendsCount(com.company.facebook.test.FbClientTest):
Received Facebook error response of type OAuthException: (#604) Can't
lookup all friends of 649390517. Can only lookup for the logged in
user or the logged in user's friends that are users of your app.
That error message seems pretty clear, you can't access friends-of-friends via the API unless the other friend also uses your app.
You can however check for mutual friends between your app's user and any arbitrary user ID.
To do that, make an API call to
/USER_ID/mutualfriends/OTHER_USER_ID
Where USER_ID is the user who's authorised your app, and OTHER_USER_ID is the user you want to check for mutual friends with.
I'm using the org.jboss.seam.security.openid.OpenId class to login user's to my seam webapp. Currently I'm saving the validatedId (openid.getValidatedId()) into the database, and asking the user to provide their own email address and first and last name after logging in. I'm using Google, Yahoo, AOL, and MyOpenID for the openId Providers.
Is there any way to retrieve the email address and or first/last name of the user without having them enter this in manually?
I had a quick glance at the OpenId class in Seam 2.2.0.GA and it already contains some tentative code for retrieving the user email address.
The code already ask for an email address when the user logs in.
protected String authRequest(String userSuppliedString, String returnToUrl)
throws IOException
{
...
// Attribute Exchange example: fetching the 'email' attribute
FetchRequest fetch = FetchRequest.createFetchRequest();
fetch.addAttribute("email",
"http://schema.openid.net/contact/email", // type URI
true); // required
And there's commented code for extracting that email from the response.
public String verifyResponse(HttpServletRequest httpReq)
{
...
// AuthSuccess authSuccess =
// (AuthSuccess) verification.getAuthResponse();
// if (authSuccess.hasExtension(AxMessage.OPENID_NS_AX)) {
// FetchResponse fetchResp = (FetchResponse) authSuccess
// .getExtension(AxMessage.OPENID_NS_AX);
//
// List emails = fetchResp.getAttributeValues("email");
// String email = (String) emails.get(0);
// }
In any case you can probably use that code as a starting point.
Edit:
I managed to write a small demo based on the Seam OpenID sample. I unfortunately had to copy/paste the code from the Seam OpenId component since the existing bits of attribute-exchange code were incomplete and there's no obvious way to extend it.
I don't know if copy/pasting LGPL code is acceptable in your project. In any case Seam's OpenID component is only a thin wrapper around the openid4java library and could be rewritten easily.
Google, Yahoo, AOL, and MyOpenID
I attempted to fetch the email address and personal name of users signing-in from the four providers you mentioned. Here are the result of my little experiment.
From Google I obtain:
Gmail email address
First name
Last name
From AOL:
Email (default to AOL email but the user can type-in another)
From Yahoo:
Yahoo email address
Full Name (all in one string)
From myOpenID:
Email (if the user has filed one in his profile)
Full name (if the user has filed one in his profile)
I had to include both the http://schema.openid.net/contact/email and http://axschema.org namspaces in the request to get a response from all the providers.