我想收到来自https://www.googleapis.com/plus/v1/people/me电话的电子邮件。我收到很多信息,但不是电子邮件。有人可以帮忙吗?
HttpGet request = new HttpGet("https://www.googleapis.com/plus/v1/people/me?scope=https://www.googleapis.com/auth/userinfo.email");
request.setHeader("Authorization", "Bearer <access_token>");
HttpResponse response = client.execute(request);
答案 0 :(得分:8)
编辑:已于2013年12月更新为改进的Google+登录选项的一部分 - 您现在可以通过Google+个人资料回复获取电子邮件地址。
只要您拥有电子邮件或https://www.googleapis.com/auth/plus.profile.emails.read范围,您就会收到来自此端点的电子邮件。有关详细信息,请参阅https://developers.google.com/+/web/people/#retrieve_an_authenticated_users_email_address。
var request = gapi.client.plus.people.get( {'userId' : 'me'} );
request.execute(function(person) {
if(person['emails']) {
console.log(person['emails'][0].value);
}
});
答案 1 :(得分:1)
我找到了答案。 我的目标也是这个。 我们可以成功地做到这一点:)
你需要:
的accessToken
以上两个之后只需向https://www.googleapis.com/oauth2/v2/userinfo
发出HTTP GET请求但添加了标题“授权:持票人<accessToken>
”
package com.google.plus.samples.photohunt.custom;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
public class NetClientGet {
// http://localhost:8080/RESTfulExample/json/product/get
public static void makeRequest(String access_token) {
try {
URL url = new URL("https://www.googleapis.com/oauth2/v2/userinfo");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("Authorization", "Bearer "+access_token);
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/json");
if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode());
}
BufferedReader br = new BufferedReader(new InputStreamReader(
(conn.getInputStream())));
String output;
System.out.println("REST call made. Output from Server .... \n");
while ((output = br.readLine()) != null) {
System.out.println(output);
}
conn.disconnect();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}