Javascript 在PHP中访问GAPI授权?

Javascript 在PHP中访问GAPI授权?,javascript,php,oauth-2.0,google-api,Javascript,Php,Oauth 2.0,Google Api,使用下面的JavaScript代码,我授权自己访问GoogleAPI。我使用它来使用JavaScript设置span元素的内容。但是,我还需要使用PHP将这些数据保存到MySql数据库中。如何从PHP代码中的JavaScript访问授权?以下是JavaScript代码: // Client ID and API key from the Developer Console var CLIENT_ID = "XXX.apps.googleusercontent.com"; var API_KEY

使用下面的JavaScript代码,我授权自己访问GoogleAPI。我使用它来使用JavaScript设置span元素的内容。但是,我还需要使用PHP将这些数据保存到MySql数据库中。如何从PHP代码中的JavaScript访问授权?以下是JavaScript代码:

// Client ID and API key from the Developer Console
var CLIENT_ID = "XXX.apps.googleusercontent.com";
var API_KEY = "XXX";

// Array of API discovery doc URLs for APIs used by the quickstart
var DISCOVERY_DOCS = ["https://www.googleapis.com/discovery/v1/apis/gmail/v1/rest"];

// Authorization scopes required by the API; multiple scopes can be
// included, separated by spaces.
var SCOPES = "https://mail.google.com/ https://www.googleapis.com/auth/userinfo.email";

/**
 *  On load, called to load the auth2 library and API client library.
 */
function handleClientLoad() {
  gapi.load("client:auth2", initClient);
}

/**
 *  Initializes the API client library and sets up sign-in state
 *  listeners.
 */
function initClient() {
  gapi.client.init({
    apiKey: API_KEY,
    clientId: CLIENT_ID,
    discoveryDocs: DISCOVERY_DOCS,
    scope: SCOPES
  }).then(function () {
    document.getElementById("email").innerHTML = gapi.auth2.getAuthInstance().currentUser.get().getBasicProfile().getEmail();
  });
}

您可以通过php授权用户。此外,如果确实需要这样做,您可以使用AJAX请求发送数据。

问题是,我不想对用户进行两次授权,我需要在同一页面上使用JavaScript和PHP进行授权。