Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从日历API返回日期和时间数组_Javascript_Jquery_Google Calendar Api_Oauth2 Playground - Fatal编程技术网

Javascript 从日历API返回日期和时间数组

Javascript 从日历API返回日期和时间数组,javascript,jquery,google-calendar-api,oauth2-playground,Javascript,Jquery,Google Calendar Api,Oauth2 Playground,对于设置JavaScript google日历API调用,没有清晰、简洁且易于遵循的示例 我发现一个例子,我试图使用插入我的OAuth密钥,但它不起作用。 要查看具体错误,请访问并打开控制台 <script type="text/javascript"> // Enter an API key from the Google API Console: // https://console.developers.google.com/apis/credentials v

对于设置JavaScript google日历API调用,没有清晰、简洁且易于遵循的示例

我发现一个例子,我试图使用插入我的OAuth密钥,但它不起作用。 要查看具体错误,请访问并打开控制台

<script type="text/javascript">
  // Enter an API key from the Google API Console:
  //   https://console.developers.google.com/apis/credentials
  var apiKey = 'mXMq9NAQ9EOzdgleTTy4wobx';
  // Enter the API Discovery Docs that describes the APIs you want to
  // access. In this example, we are accessing the People API, so we load
  // Discovery Doc found here: https://developers.google.com/people/api/rest/
  var discoveryDocs = ["https://www.googleapis.com/calendar/v3/calendars/torontohomecleaning12@gmail.com/events"];
  // Enter a client ID for a web application from the Google API Console:
  //   https://console.developers.google.com/apis/credentials?project=_
  // In your API Console project, add a JavaScript origin that corresponds
  //   to the domain where you will be running the script.
  var clientId = '646125501608-jtauc86qulpebg2oh49k4qglfjui82gc.apps.googleusercontent.com';
  // Enter one or more authorization scopes. Refer to the documentation for
  // the API or https://developers.google.com/people/v1/how-tos/authorizing
  // for details.
  var scopes = 'events';
  var authorizeButton = document.getElementById('authorize-button');
  var signoutButton = document.getElementById('signout-button');
  function handleClientLoad() {
    // Load the API client and auth2 library
    gapi.load('client:auth2', initClient);
  }
  function initClient() {
    gapi.client.init({
        apiKey: apiKey,
        discoveryDocs: discoveryDocs,
        clientId: clientId,
        scope: scopes
    }).then(function () {
      // Listen for sign-in state changes.
      gapi.auth2.getAuthInstance().isSignedIn.listen(updateSigninStatus);
      // Handle the initial sign-in state.
      updateSigninStatus(gapi.auth2.getAuthInstance().isSignedIn.get());
      authorizeButton.onclick = handleAuthClick;
      signoutButton.onclick = handleSignoutClick;
    });
  }
  function updateSigninStatus(isSignedIn) {
    if (isSignedIn) {
      authorizeButton.style.display = 'none';
      signoutButton.style.display = 'block';
      makeApiCall();
    } else {
      authorizeButton.style.display = 'block';
      signoutButton.style.display = 'none';
    }
  }
  function handleAuthClick(event) {
    gapi.auth2.getAuthInstance().signIn();
  }
  function handleSignoutClick(event) {
    gapi.auth2.getAuthInstance().signOut();
  }
  // Load the API and make an API call.  Display the results on the screen.
  function makeApiCall() {
    gapi.client.people.people.get({
      'resourceName': 'people/me',
      'requestMask.includeField': 'person.names'
    }).then(function(resp) {
      var p = document.createElement('p');
      var name = resp.result.names[0].givenName;
      p.appendChild(document.createTextNode('Hello, '+name+'!'));
      document.getElementById('content').appendChild(p);
    });
  }
</script>
<script async defer src="https://apis.google.com/js/api.js" 
  onload="this.onload=function(){};handleClientLoad()" 
  onreadystatechange="if (this.readyState === 'complete') this.onload()">
</script>

//从Google API控制台输入API密钥:
//   https://console.developers.google.com/apis/credentials
var apiKey='mXMq9NAQ9EOzdgleTTy4wobx';
//输入描述所需API的API发现文档
//进入。在本例中,我们正在访问People API,因此我们加载
//在此处找到发现文档:https://developers.google.com/people/api/rest/
var discoveryDocs=[”https://www.googleapis.com/calendar/v3/calendars/torontohomecleaning12@gmail.com/events“];
//从Google API控制台输入web应用程序的客户端ID:
//   https://console.developers.google.com/apis/credentials?project=_
//在API控制台项目中,添加对应的JavaScript源代码
//到将运行脚本的域。
var clientId='646125501608-jtauc86qulpebg2oh49k4qglfjui82gc.apps.googleusercontent.com';
//输入一个或多个授权范围。有关详细信息,请参阅文档
//API或https://developers.google.com/people/v1/how-tos/authorizing
//详情请参阅。
变量范围='事件';
var authorizeButton=document.getElementById('authorized-button');
var signburatton=document.getElementById('signout-button');
函数handleClientLoad(){
//加载API客户端和auth2库
load('client:auth2',initClient);
}
函数initClient(){
gapi.client.init({
阿皮基:阿皮基,
discoveryDocs:discoveryDocs,
clientId:clientId,
范围:范围
}).然后(函数(){
//侦听登录状态的更改。
gapi.auth2.getAuthInstance().isSignedIn.listen(updateSigninStatus);
//处理初始登录状态。
updateSigninStatus(gapi.auth2.getAuthInstance().isSignedIn.get());
authorizeButton.onclick=handleAuthClick;
SignerButton.onclick=handleSignoutClick;
});
}
函数updateSigninStatus(isSignedIn){
如果(伊西涅丁){
authorizeButton.style.display='none';
signexputton.style.display='block';
makeApiCall();
}否则{
authorizeButton.style.display='block';
signexputton.style.display='none';
}
}
函数handleAuthClick(事件){
gapi.auth2.getAuthInstance().signIn();
}
函数handleSignoutClick(事件){
gapi.auth2.getAuthInstance().signOut();
}
//加载API并进行API调用。在屏幕上显示结果。
函数makeApiCall(){
gapi.client.people.people.get({
'resourceName':'people/me',
“requestMask.includeField”:“person.names”
}).然后(功能(resp){
var p=document.createElement('p');
var name=resp.result.names[0].givenName;
p、 appendChild(document.createTextNode('Hello',+name+'!');
document.getElementById('content').appendChild(p);
});
}
问题是:我找不到一个复制粘贴的例子,在这个例子中,我只需要交换OAuthkey和clientID,这样我就可以返回我的Google日历上当前的日期和时间数组,我是它的所有者

最终目标:能够根据返回的日期数组过滤jQuery日期选择器中断日期。然后,根据当天已预订的时段(如果有可用的时段)筛选时段下拉菜单


我无法通过这第一步让所有人都互相交谈。

我看到您正在使用Google People API。对于您请求的呼叫(获取当前谷歌日历上的日期和时间数组),我建议您使用谷歌日历API(而不是People API)。您可以遵循全面的快速入门。对于您的特定需求,您还可以转到API页面,在那里您可以使用API调用生成器生成必要的Javascript代码以使其正常工作

这是它为您需要发出的请求生成的代码:


/**
*calendar.events.list的JavaScript代码示例
*请参阅本地运行API Explorer代码示例的说明:
* https://developers.google.com/explorer-help/guides/code_samples#javascript
*/
函数身份验证(){
返回gapi.auth2.getAuthInstance()
.signIn({范围:https://www.googleapis.com/auth/calendar https://www.googleapis.com/auth/calendar.events https://www.googleapis.com/auth/calendar.events.readonly https://www.googleapis.com/auth/calendar.readonly"})
.then(function(){console.log(“登录成功”);},
函数(err){console.error(“错误登录”,err);});
}
函数loadClient(){
gapi.client.setApiKey(“您的API密钥”);
返回gapi.client.load(“https://content.googleapis.com/discovery/v1/apis/calendar/v3/rest")
.then(function(){console.log(“为API加载的GAPI客户端”);},
函数(err){console.error(“为API加载GAPI客户端时出错”,err);});
}
//在调用此方法之前,请确保已加载客户端并完成登录。
函数execute(){
返回gapi.client.calendar.events.list({
“日历ID”:“您的日历ID”
})
.然后(功能(响应){
//在这里处理结果(response.result具有解析的主体)。
控制台日志(“响应”,响应);
},
函数(err){console.error(“executeerror”,err);});
}
load(“客户端:auth2”,函数(){
gapi.auth2.init({client_id:“YOUR_client_id”});
});
授权加载
执行
您只需设置API密钥、客户端ID和日历ID即可使其正常工作。如果您有任何其他问题,请随时回复


注意。

现在的问题是OAuth2屏幕提示