Javascript 通过谷歌日历浏览谷歌任务
由于gmail和任务api并非无处不在(例如:一些公司屏蔽gmail但不屏蔽日历),有没有办法通过日历web界面取消google任务 我编写了一个如下所示的用户脚本,但我发现它太脆弱了:Javascript 通过谷歌日历浏览谷歌任务,javascript,jquery,google-calendar-api,web-scraping,Javascript,Jquery,Google Calendar Api,Web Scraping,由于gmail和任务api并非无处不在(例如:一些公司屏蔽gmail但不屏蔽日历),有没有办法通过日历web界面取消google任务 我编写了一个如下所示的用户脚本,但我发现它太脆弱了: // List of div to hide idlist = [ 'gbar', 'logo-container', ... ]; // Hiding by id function displayNone(idlist) { for each (id in idlist) {
// List of div to hide
idlist = [
'gbar',
'logo-container',
...
];
// Hiding by id
function displayNone(idlist) {
for each (id in idlist) {
document.getElementById(id).style.display = 'none';
}
}
我建议解析您希望看到的日历的Atom提要。通过选择选项Gear>Calendar Settings,然后选择calendars选项卡,然后选择所需的日历,可以获取各个日历的提要。从日历详细信息屏幕,您可以获得Atom(XML)提要、iCal提要或HTML/Javascript日历。Google Tasks API现在可用。您可以通过HTTP查询获得任务列表,结果以JSON返回。这里有一个关于如何在Google App Engine上编写Google Tasks webapp的分步示例 示例webapp如下所示:
from google.appengine.dist import use_library
use_library('django', '1.2')
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp.util import run_wsgi_app
from apiclient.discovery import build
import httplib2
from oauth2client.appengine import OAuth2Decorator
import settings
decorator = OAuth2Decorator(client_id=settings.CLIENT_ID,
client_secret=settings.CLIENT_SECRET,
scope=settings.SCOPE,
user_agent='mytasks')
class MainHandler(webapp.RequestHandler):
@decorator.oauth_aware
def get(self):
if decorator.has_credentials():
service = build('tasks', 'v1', http=decorator.http())
result = service.tasks().list(tasklist='@default').execute()
tasks = result.get('items', [])
for task in tasks:
task['title_short'] = truncate(task['title'], 26)
self.response.out.write(template.render('templates/index.html',
{'tasks': tasks}))
else:
url = decorator.authorize_url()
self.response.out.write(template.render('templates/index.html',
{'tasks': [],
'authorize_url': url}))
def truncate(string, length):
return string[:length] + '...' if len(string) > length else string
application = webapp.WSGIApplication([('/', MainHandler)], debug=True)
def main():
run_wsgi_app(application)
请注意,首先需要在API控制台启用Google Tasks API。你试过什么?很抱歉,这不是一个
requirements=>code
引擎。我曾尝试使用greasmonkey/jquery脚本来隐藏所有不必要的日历div(),但我不喜欢这个解决方案(它很脆弱)。为了理解ajax调用,我试图查看GoogleCalendarJS代码,但它太复杂了。如果有一种更简单/干净的方式来访问我的数据,那就太好了。