简体   繁体   English

如何在不使用OAuth 2.0的情况下使用Google Calendar API

[英]How to Use Google Calendar API without OAuth 2.0

I wanted to know if there is any way to use google calendar api without using OAuth. 我想知道是否可以在不使用OAuth的情况下使用Google Calendar API。 For example only to write in my public calendar from a web application in Net Beans. 例如,仅从Net Beans中的Web应用程序写入我的公共日历中。 I just need to write to my calendars, not in other people's calendars. 我只需要写我的日历,而不用别人的日历。 Try using Aouth 2.0 but did not work. 尝试使用Aouth 2.0,但无效。

Except for displaying a public calendar, you'll always need authorization to perform operations on the Calendar API. 除了显示公共日历之外,您始终需要获得授权才能在Calendar API上执行操作。 If you check the events.insert page, you'll see immediately that this requires Authorization. 如果您查看events.insert页面,您将立即看到这需要授权。 Even using service accounts which bypasses the manual authorization, uses OAuth. 即使使用绕过手动授权的服务帐户 ,也要使用OAuth。

I am using java in netbeans. 我在netbeans中使用Java。 my application is a type of web service, I return some json using jsp. 我的应用程序是一种Web服务,我使用jsp返回了一些json。 jsp call the function that returns my upcoming events on my calendar. jsp调用返回我日历上即将发生的事件的函数。 but when I try to authorize nothing happens. 但是当我尝试授权时,什么也没发生。 this is my code. 这是我的代码。 (I have all the necessary libraries). (我有所有必要的库)。

  public static Credential authorize() throws IOException {
    Credential credential;

    try {

        GoogleClientSecrets clientSecrets = new GoogleClientSecrets();
        GoogleClientSecrets.Details det = new GoogleClientSecrets.Details();
        det.setClientId("my id");
        det.setClientSecret("my secret");
        det.setRedirectUris(Arrays.asList("urn:ietf:wg:oauth:2.0:oob"));
        clientSecrets.setInstalled(det);

        GoogleAuthorizationCodeFlow flow =  new      GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
                .setDataStoreFactory(DATA_STORE_FACTORY)
                .setAccessType("offline")
                .build();
        credential = new AuthorizationCodeInstalledApp(flow, new                                                  LocalServerReceiver()).authorize("user");

    } catch (Exception ex) {
        credential = null;
    }

    return credential;
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM