2014-03-29 19 views
0
 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; 
     } 

這是代碼,我可以得到用戶數據當用戶sign in與他們的Google+帳戶到我的網站。 Everthing很好。 我可以得到用戶數據(id,name,gender,picture,link,family_name,locale),但只有我不能發郵件。當用戶用他們的Google+帳戶登錄時,我可以獲取所有數據,但只能發送電子郵件。電子郵件= null和verified_email = false

email=null 
verified_email=false 

但是昨天並不是這樣。我也可以得到email

有誰知道我的錯誤在哪裏?

@@@。 。 。 我只用 https://www.googleapis.com/auth/plus.profile.emails.read作爲scopestring URL=string.Format("https://www.googleapis.com/plus/v1/people/me?access_token={0}‌​‌​", googleresponse.access_token);創建HttpWebRequest。 我可以得到所有用戶的數據,也可以email

我在這裏寫了這個,因爲可能是其他用戶可以使用。

+0

和'scope = https:// www.googleapis.com/auth/plus.login' – Jeyhun

回答

1

您還需要https://www.googleapis.com/auth/plus.profile.emails.read範圍。有關更多詳細信息,請參閱https://developers.google.com/+/web/people/#retrieve_an_authenticated_users_email_addresshttps://developers.google.com/+/api/oauth#email-scopes

更新

要清楚,你仍然需要在除了我上面提到的plus.profile.emails範圍https://www.googleapis.com/auth/plus.login範圍。

你仍然使用plus.people.get端點在https://developers.google.com/+/api/latest/people/get

描述你應該不再使用userinfo終點 - 那些已被棄用,並將於九月被刪除。

+0

在C#代碼中,我應該使用哪個端點? (用於創建httpwebrequest) – Jeyhun

+0

響應已更新 – Prisoner

+0

我使用了https://www.googleapis.com/plus/v1/people/me?access_token= {0}'endpoit 和 'https://www.googleapis.com /auth/plus.login https:// www.googleapis.com/auth/plus.profile.emails.read'作用域。 而且我可以獲得我需要的所有數據。 這是錯誤的嗎? 我希望這個端點不會被刪除。 – Jeyhun

相關問題