[英]When User sing in with their Google+ account, I can get all data, but only can't email. email=null and verified_email=false
string URL=string.Format("https://www.googleapis.com/oauth2/v1/userinfo?access_token={0}", googleresponse.access_token);
private A GetGoogleUser<A>(string urluser) where A:class
{
A user = null;
if (googleresponse != null && !string.IsNullOrEmpty(googleresponse.access_token))
{
HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(urluser);
HttpWebResponse webresponse = (HttpWebResponse)webrequest.GetResponse();
if (((HttpWebResponse)webresponse).StatusCode == HttpStatusCode.OK)
{
using (Stream recieveuser = webresponse.GetResponseStream())
{
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
using (StreamReader readstream = new StreamReader(recieveuser, encode))
{
user = new JavaScriptSerializer().Deserialize<A>(readstream.ReadToEnd());
webresponse.Close();
readstream.Close();
}
}
}
}
return user;
}
It is code that I can get User data When User sign in
with their Google+
account to my website. 当用户使用其
Google+
帐户sign in
我的网站时,我可以获取该数据。 Everthing is fine. 一切都很好。 I can get User data
(id,name,gender,picture,link,family_name,locale)
, but only I can't email. 我可以获取用户数据
(id,name,gender,picture,link,family_name,locale)
,但只有我无法发送电子邮件。
email=null
verified_email=false
But yesterday it was not so. 但是昨天并非如此。 I could get
email
too. 我也可以收到
email
。
Does anyone know that where is my mistake ? 有谁知道我的错误在哪里?
@@@. @@@。 .
。 .
。 I used only
https://www.googleapis.com/auth/plus.profile.emails.read
as scope
, and string URL=string.Format("https://www.googleapis.com/plus/v1/people/me?access_token={0}", googleresponse.access_token);
我仅使用
https://www.googleapis.com/auth/plus.profile.emails.read
作为scope
和string URL=string.Format("https://www.googleapis.com/plus/v1/people/me?access_token={0}", googleresponse.access_token);
for creating HttpWebRequest
. 用于创建
HttpWebRequest
。 I can get all user's data, also email
. 我可以获取所有用户数据,也可以获取
email
。
I wrote this here because may be other users can be use. 我在这里写这个是因为可能被其他用户使用。
You also need the https://www.googleapis.com/auth/plus.profile.emails.read scope. 您还需要https://www.googleapis.com/auth/plus.profile.emails.read范围。 See https://developers.google.com/+/web/people/#retrieve_an_authenticated_users_email_address and https://developers.google.com/+/api/oauth#email-scopes for more details.
有关更多详细信息,请参见https://developers.google.com/+/web/people/#retrieve_an_authenticated_users_email_address和https://developers.google.com/+/api/oauth#email-scopes 。
Update 更新资料
To be clear, you still need the https://www.googleapis.com/auth/plus.login scope in addition to the plus.profile.emails scope I mentioned above. 需要明确的是,除了上面提到的plus.profile.emails范围外,您还需要https://www.googleapis.com/auth/plus.login范围。
You'll still use the plus.people.get
endpoint described at https://developers.google.com/+/api/latest/people/get 您仍将使用https://developers.google.com/+/api/latest/people/get中描述的
plus.people.get
端点
You should no longer use the userinfo
endpoint - those have been deprecated and will be removed in September. 您不应再使用
userinfo
终结点-已弃用了这些终结点,并将在9月将其删除。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.