如何使用JavaScript从Google日历页面获取事件ID? [英] How to get event ID from Google Calendar page with JavaScript?

查看:190
本文介绍了如何使用JavaScript从Google日历页面获取事件ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Google日历创建Google Chrome扩展程序。我想在用户访问事件编辑页面时获取事件的ID。



如何从插件的JavaScript代码获取事件ID,以便可以使用该ID来触发Calendar api v3.0。





添加额外信息
Google Calendar API日历ID和事件ID
@krishna actualy的评论显示了如何获取事件ID并且它可以正常工作。但是,如何通过 https://www.google.com/calendar/ 网址获取活动ID不在网址中( https://www.google.com/calendar / render?gsessionid = OK& eventdeb = 1 ),正如克里希纳告诉的那样。

它位于 data-eid 属性,你在屏幕截图中部分用黑色覆盖。它与base64(或base64url)等其他东西一起编码。

以下代码应解码,提取并打印事件ID(假设jQuery已加载):

 
var encoded = $(div.ep [data-eid])。attr(data-eid);
if(encoded!== undefined){
var decoded = atob(encoded);
console.log(当前事件ID:+ decoded.split()[0]);

打印如下:

 
当前事件ID:75v3thapnpd234ocglgk625frc


I am creating a Google Chrome extension for Google calendar. I want to get the ID of an event when user visits the event edit page.

How can I get the event ID from the plugin's javascript code so that I can fire Calendar api v3.0 with that ID.

Adding extra info: Google Calendar API calendar id and event id The comment by @krishna actualy shows how to get the event ID and it works. But how to get the event ID in https://www.google.com/calendar/ URL not in the URL(https://www.google.com/calendar/render?gsessionid=OK&eventdeb=1) as told by Krishna.

解决方案

It's in the data-eid attribute that you partially covered in black in the screenshot. It is encoded along with other things as base64 (or base64url).

The following code should decode, extract, and print the event ID (assuming jQuery was loaded):

var encoded = $("div.ep[data-eid]").attr("data-eid");
if (encoded !== undefined) {
  var decoded = atob(encoded);
  console.log("Current event ID: " + decoded.split(" ")[0]);
}

prints something like:

Current event ID: 75v3thapnpd234ocglgk625frc

这篇关于如何使用JavaScript从Google日历页面获取事件ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆