如何获得选定国家的国家法定节假日 [英] How to get national holidays of selected country

查看:2449
本文介绍了如何获得选定国家的国家法定节假日的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做一个应用程序,可以从列表中选择国家。当选择一个国家,看来该国的国家法定节假日的列表。

I'm making an app that can select country from a list. When pick a country, It appears a list of national holidays of that country.

我见过的<一个href="http://developer.android.com/guide/topics/providers/calendar-provider.html">CalendarProvider和谷歌日历V3 。但它似乎只提供当前用户的日历。

I've seen CalendarProvider and Google Calendar V3. But It seem only provide current user calendar.

如何获得国定假日,因为我想要的吗?任何建议还帮我

How to get national holidays as I want? Any suggestion also helped me

更新:

我发现<一href="http://stackoverflow.com/questions/13651017/accessing-google-calendar-api-with-javascript-without-authorization">this帖子可以使用JSON获取列表的节日。在这个例子中,该国code。通过日历ID定义(pt_br.brazilian#holiday@group.v.calendar.google.com)
 但我看不出有任何文档写这个。
我还发现了另外一个日历ID(en.usa#holiday@group.v.calendar.google.com)。

I've found this post which can get list holiday using json. In this example, the country code defined by calendar id (pt_br.brazilian#holiday@group.v.calendar.google.com)
But I don't see any docs write about this.
I also found another calendar id (en.usa#holiday@group.v.calendar.google.com).

时可以使用这种方式?如果是的话,我在哪里可以得到这些日历ID?

Is possible to use this way? If yes, where can I get those calendar id?

推荐答案

问题通过使用谷歌日历API V3 。我发现从想法<一href="http://stackoverflow.com/questions/13651017/accessing-google-calendar-api-with-javascript-without-authorization">this帖子。 这个节日可以从谷歌的默认假期日历。

Problem solved by using Google Calendar API V3. The idea I found from this post. The holiday can get from default holiday calendar of google.

默认假期日历的ID列表,可以发现这里,为40个国家的支持。

The ID list of default holiday calendar can be found here, support to 40 country.

的code一个和平的处理权限,并得到节日列表:

A peace of code that handle permission and get holiday list:

com.google.api.services.calendar.Calendar client = null;
        credential = GoogleAccountCredential.usingOAuth2(mContext, CalendarScopes.CALENDAR);
        credential.setSelectedAccountName(mList.get(0));
        client = getCalendarService(credential);
        do {
            com.google.api.services.calendar.model.Events events;
            events = client.events().list("en.usa#holiday@group.v.calendar.google.com").setPageToken(pageToken).execute();
            onHolidayChecked(events.getItems()); //result return here (events.getItems())
            pageToken = events.getNextPageToken();
        } while (pageToken != null);

private com.google.api.services.calendar.Calendar getCalendarService(GoogleAccountCredential credential) {
    return new com.google.api.services.calendar.Calendar.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential).build();
}

这篇关于如何获得选定国家的国家法定节假日的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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