[英]Chrome App, getting logged in user's email address
我搜索了像https://developer.chrome.com/apps/app_identity這樣的教程,但我看不到如何檢索登錄 chrome 的用戶的電子郵件地址。 我只能獲得 chrome.identity api https://developer.chrome.com/apps/identity的令牌
所以獲取令牌的示例代碼有效
chrome.identity.getAuthToken({'interactive': true}, function(token) {
console.log('user token: ' + token);
});
但從這里我如何收到電子郵件。
注意:這是針對應用程序而不是擴展程序,因此 context_script 在我的 auth 示例清單中不起作用。 另外 chrome.identity.getProfileUserInfo 適用於測試版 37,我也嘗試過,但 enail 為空。
我別無選擇,但我知道有一種方法可以獲取電子郵件。
哈哈回答我自己的問題。
簡短回答:您只需在清單文件中添加電子郵件的范圍
長答案:我不得不使用google plus api。 Google 已棄用 OpenID 2.0,現在根據https://developers.google.com/accounts/docs/OpenID2使用 Google Plus 登錄和 api。 所以我在上面提到,我沒有使用 xhr method = "GET, url='ht tps://www.googleapis.com/plus/v1/people/me' 來獲取調用 Google Plus 的電子郵件地址。所以響應僅顯示姓名、性別、圖像等基本信息,但沒有顯示電子郵件。為了獲取電子郵件,您必須像示例一樣在清單文件中添加電子郵件令牌
"permissions": ["identity",
...,
],
"oauth2": {
// client_id below is specifc to the application key. Follow the
// documentation to obtain one for your app.
"client_id": xyz,
"scopes": ["https://www.googleapis.com/auth/plus.login",
"https://www.googleapis.com/auth/userinfo.email"] **<-this one**
}
....
現在,當 ypou call xhr method = "GET, url='htt ps://www.googleapis.com/plus/v1/people/me' 時,在您的響應中,您將獲得基本用戶信息和電子郵件
作為更新,這里有一種更簡單的方式來獲取電子郵件:
您必須將“身份”和“身份.email”添加到清單文件的權限部分。
有了這個,使用getProfileUserInfo應該可以解決問題:
chrome.identity.getAuthToken({'interactive': true}, function(token) { chrome.identity.getProfileUserInfo( function(info){console.log(info.email)} ); }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.