如何自动验证google javascript api?RESTAPI

如何自动验证google javascript api?RESTAPI,javascript,php,google-api,Javascript,Php,Google Api,我正在使用php。我想在我的应用程序中使用一些javascript api函数。因此,任何人都知道如何自动验证此过程: <!--Add a button for the user to click to initiate auth sequence --> <button id="authorize-button" style="visibility: hidden">Authorize</button> <script type="text/javas

我正在使用php。我想在我的应用程序中使用一些javascript api函数。因此,任何人都知道如何自动验证此过程:

<!--Add a button for the user to click to initiate auth sequence -->
<button id="authorize-button" style="visibility: hidden">Authorize</button>
<script type="text/javascript">

  var clientId = '837050751313';

  var apiKey = 'AIzaSyAdjHPT5Pb7Nu56WJ_nlrMGOAgUAtKjiPM';

  var scopes = 'https://www.googleapis.com/auth/plus.me';

  function handleClientLoad() {
    // Step 2: Reference the API key
    gapi.client.setApiKey(apiKey);
    window.setTimeout(checkAuth,1);
  }

  function checkAuth() {
    gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: true}, handleAuthResult);
  }

  function handleAuthResult(authResult) {
    var authorizeButton = document.getElementById('authorize-button');
    if (authResult && !authResult.error) {
      authorizeButton.style.visibility = 'hidden';
      makeApiCall();
    } else {
      authorizeButton.style.visibility = '';
      authorizeButton.onclick = handleAuthClick;
    }
  }

  function handleAuthClick(event) {
    // Step 3: get authorization to use private data
    gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: false}, handleAuthResult);
    return false;
  }

  // Load the API and make an API call.  Display the results on the screen.
  function makeApiCall() {
    // Step 4: Load the Google+ API
    gapi.client.load('plus', 'v1').then(function() {
      // Step 5: Assemble the API request
      var request = gapi.client.plus.people.get({
        'userId': 'me'
      });
      // Step 6: Execute the API request
      request.then(function(resp) {
        var heading = document.createElement('h4');
        var image = document.createElement('img');
        image.src = resp.result.image.url;
        heading.appendChild(image);
        heading.appendChild(document.createTextNode(resp.result.displayName));

        document.getElementById('content').appendChild(heading);
      }, function(reason) {
        console.log('Error: ' + reason.result.error.message);
      });
    });
  }
</script>
// Step 1: Load JavaScript client library
<script src="https://apis.google.com/js/client.js?onload=handleClientLoad"></script>

授权
var clientId='837050751313';
var apiKey='AIzaSyAdjHPT5Pb7Nu56WJ_nlrMGOAgUAtKjiPM';
var作用域https://www.googleapis.com/auth/plus.me';
函数handleClientLoad(){
//步骤2:引用API密钥
gapi.client.setApiKey(apiKey);
setTimeout(checkAuth,1);
}
函数checkAuth(){
auth.authorize({client_id:clientId,scope:scopes,immediate:true},handleAuthResult);
}
函数handleAuthResult(authResult){
var authorizeButton=document.getElementById('authorized-button');
if(authResult&!authResult.error){
authorizeButton.style.visibility='hidden';
makeApiCall();
}否则{
authorizeButton.style.visibility='';
authorizeButton.onclick=handleAuthClick;
}
}
函数handleAuthClick(事件){
//步骤3:获得使用私有数据的授权
auth.authorize({client_id:clientId,scope:scopes,immediate:false},handleAuthResult);
返回false;
}
//加载API并进行API调用。在屏幕上显示结果。
函数makeApiCall(){
//步骤4:加载Google+API
load('plus','v1')。然后(function(){
//步骤5:组装API请求
var request=gapi.client.plus.people.get({
“userId”:“我”
});
//步骤6:执行API请求
请求。然后(功能(resp){
var heading=document.createElement('h4');
var image=document.createElement('img');
image.src=resp.result.image.url;
标题.附加子项(图像);
heading.appendChild(document.createTextNode(resp.result.displayName));
document.getElementById('content').appendChild(标题);
},功能(原因){
console.log('错误:'+原因.结果.错误.消息);
});
});
}
//步骤1:加载JavaScript客户端库

我有.json和.p12文件进行身份验证,但我只想直接访问api函数,而不是重定向到google进行权限访问。

当使用google+api或其他访问用户特定数据(如Gmail、日历)的api时,您需要使用OAuth客户端并向用户请求访问其数据的权限(即“重定向到google以获得访问权限”),或者使用服务帐户


服务帐户是代替真实用户使用的机器人帐户。如果您决定使用服务帐户,则需要使用您提到的JSON或P12密钥。从JavaScript代码中使用服务帐户需要大量工作,而且通常是不安全的,因为您将使每个人都可以访问您的服务帐户密钥。如果要使用服务帐户,应该从服务器调用API。

我已经使用过php客户端API。但我想隐藏电子表格列,而泰语在php客户端api中是不可能的。是的,我想访问谷歌的服务。通过javascript api可以隐藏工作表的列。