【问题标题】:Google calendar get events谷歌日历获取事件
【发布时间】:2016-05-13 09:27:18
【问题描述】:

我正在使用此代码并从日历中获取事件,它工作正常,但我想从谷歌帐户日历中获取事件。例如,我想获取 (deepakcando90@gmail.com)google 日历帐户事件也?我知道可以但不知道如何实现?

      public static void readCalendarEvent(Context context) throws ParseException {
    ContentResolver contentResolver = context.getContentResolver();
    Calendar calendar = Calendar.getInstance();
    String dtstart = "dtstart";
    String dtend = "dtend";


    SimpleDateFormat    displayFormatter = new SimpleDateFormat("EEEE, MMMM dd, yyyy");

     stime=displayFormatter.format(calendar.getTime());     

    SimpleDateFormat startFormatter = new SimpleDateFormat("MM/dd/yy");
    String dateString = startFormatter.format(calendar.getTime());

    long after = calendar.getTimeInMillis();
    SimpleDateFormat formatterr = new SimpleDateFormat("hh:mm:ss MM/dd/yy");
    Calendar endOfDay = Calendar.getInstance();
    Date dateCCC = formatterr.parse("47:59:59 " + dateString);
    endOfDay.setTime(dateCCC);



    cursor = contentResolver.query(Uri.parse("content://com.android.calendar/events"), (new String[] { "calendar_id", "title", "description", "dtstart", "dtend", "eventLocation" }), "(" + dtstart + ">" + after + " and " + dtend + "<" + endOfDay.getTimeInMillis() + ")", null, "dtstart ASC");
    gCalendar = new ArrayList<GoogleCalendar>();
    try {
        System.out.println("Count=" + cursor.getCount());

        if (cursor.getCount() > 0) {

            System.out.println("the control is just inside of the cursor.count loop");
            while (cursor.moveToNext()) {
                GoogleCalendar googleCalendar = new GoogleCalendar();
                gCalendar.add(googleCalendar);
                int calendar_id = cursor.getInt(0);
                googleCalendar.setCalendar_id(calendar_id);
                String title = cursor.getString(1);
                googleCalendar.setTitle(title);
                String description = cursor.getString(2);
                googleCalendar.setDescription(description);
                String dtstart1 = cursor.getString(3);
                googleCalendar.setDtstart(dtstart1);
                String dtend1 = cursor.getString(4);
                googleCalendar.setDtend(dtend1);
                String eventlocation = cursor.getString(5);
                googleCalendar.setEventlocation(eventlocation);

            }
        }
    } catch (AssertionError ex) {
        ex.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

}

【问题讨论】:

    标签: events get google-calendar-api


    【解决方案1】:

    您可以尝试OAuth 2.0 service accounts 以正确访问用户帐户。使用服务帐户可让您模拟用户并代表他们执行操作。

    以应用程序访问域日历

    如果应用使用service account 进行身份验证,则无需用户凭据即可访问域拥有的日历。服务帐户必须具有使用 domain-wide authority delegation 的必要访问权限。要模拟用户帐户,请使用 GoogleCredential 工厂的 setServiceAccountUser 方法指定用户帐户的电子邮件地址。

    我希望它有所帮助。祝你好运:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-08
      相关资源
      最近更新 更多