2017-07-26 33 views
0

我正在嘗試獲取經過身份驗證的用戶的電子郵件地址。Google OAuth2 API v2 userinfo對於電子郵件始終返回空值

我已經做了驗證與範圍

email 
profile 
https://www.googleapis.com/auth/plus.login 
https://www.googleapis.com/plus/v1/people/me 
https://www.googleapis.com/auth/userinfo.email 

此呼籲電子郵件,但名稱,鏈接,圖片等返回null被填充:

Userinfoplus userinfo2 = oauth2.userinfo().v2().me().get().execute(); 
log.info(userinfo2.toString()); 

輸出:

{ 
    "family_name" : "Homlish", 
    "gender" : "male", 
    "given_name" : "Paul", 
    "id" : "107004799409225320539", 
    "link" : "https://plus.google.com/107004799409225320539", 
    "locale" : "en", 
    "name" : "Paul Homlish", 
    "picture" : "https://lh4.googleusercontent.com/-bCRlXUqr__E/AAAAAAAAAAI/AAAAAAAABR8/LQCliyz_jgI/photo.jpg" 
} 

檢查我可以看到一個電子郵件字段,但它是空的。

任何想法我失蹤?

儘管我使用的範圍不會提示用戶額外的權限,但是有沒有可以刪除的範圍?

感謝, 保羅

+0

您能向我們展示Google(HTTP狀態)給出的響應嗎? – Cylexx

+0

切換到HttpResponse r = oauth2.userinfo()。v2()。me()。get()。executeUnparsed();我看到200,「OK」 – phomlish

+0

你的回覆包含這樣的「電子郵件」? ' 「種」: 「加#人」, 「ETAG」: 「\」 rthtrsgd \ 「」, 「性別」: 「男」, 「電子郵件」: { 「值」:「28 @ gmail.com」, 「類型」: 「帳戶」 } ], 「的objectType」: 「人」, 「ID」: 「'XXXXXXXXXXXXXXXXX」,' – Cylexx

回答

1

通過設定範圍, '電子郵件',認證,並使用com.google.api.client.googleapis.auth.oauth2.GoogleCredential和com.google.api.services.oauth2。 Oauth2我能夠接收電子郵件:

 GoogleCredential credential = new GoogleCredential().setAccessToken(tokenFromAuthentication); 
     Oauth2 oauth2 = new Oauth2.Builder(new NetHttpTransport(), new JacksonFactory(), credential) 
       .setApplicationName("Oauth2") 
       .build(); 
     Userinfoplus userinfo = oauth2.userinfo().get().execute(); 
相關問題