-1
我想在使用gmail登錄的Ionic框架中訪問用戶電子郵件地址和個人資料圖片網址。使用訪問令牌獲取電子郵件地址Google Ionic
繼OAuth的代碼可以幫助登陸用戶和返回的訪問令牌
$http.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
var requestToken = "";
var accessToken = "";
var clientId = "example";
var clientSecret = "xxxx";
$scope.LoginwithGoogle = function() {
var ref = window.open('https://accounts.google.com/o/oauth2/auth?client_id=' + clientId + '&redirect_uri=http://localhost/callback&scope=https://www.googleapis.com/auth/urlshortener&approval_prompt=force&response_type=code&access_type=offline', '_blank', 'location=no');
ref.addEventListener('loadstart', function(event) {
if ((event.url).startsWith("http://localhost/callback")) {
requestToken = (event.url).split("code=")[1];
$http({
method: "post",
url: "https://accounts.google.com/o/oauth2/token",
data: "client_id=" + clientId + "&client_secret=" + clientSecret + "&redirect_uri=http://localhost/callback" + "&grant_type=authorization_code" + "&code=" + requestToken
})
.success(function(data) {
var accessToken = data.access_token;
})
.error(function(data, status) {
alert("ERROR: " + data);
});
ref.close();
}
});
我如何使用此訪問令牌獲取用戶的電子郵件地址和檔案相片嗎?