谷歌日历API授权错误



我是新来的谷歌项目,我必须在我的项目中集成谷歌日历和谷歌任务。为此,我参考[https://developers.google.com/google-apps/calendar/instantiate][1]。我已经添加了:

google play services作为库google-api-services-calendar-v3-rev81-java-1.18.0-rc。

但是它显示错误"键入com.google.api.client.auth.oauth2.draft10. "无法解析AuthorizationRequestUrl。它是从必需的.class文件"

间接引用的。下面是我的代码:
    String clientId = "YOUR_CLIENT_ID";
    String clientSecret = "YOUR_CLIENT_SECRET";
    // Or your redirect URL for web based applications.
    String redirectUrl = "urn:ietf:wg:oauth:2.0:oob";
    String scope = "https://www.googleapis.com/auth/calendar";
    // Step 1: Authorize -->
    String authorizationUrl = new GoogleAuthorizationRequestUrl(clientId,
            redirectUrl, scope).build();
    // Point or redirect your user to the authorizationUrl.
    System.out.println("Go to the following link in your browser:");
    System.out.println(authorizationUrl);
    // Read the authorization code from the standard input stream.
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    System.out.println("What is the authorization code?");
    String code = in.readLine();
    // End of Step 1 <--
    // Step 2: Exchange -->
    AccessTokenResponse response = new GoogleAuthorizationCodeGrant(
            httpTransport, jsonFactory, clientId, clientSecret, code,
            redirectUrl).execute();
    // End of Step 2 <--
    GoogleAccessProtectedResource accessProtectedResource = new GoogleAccessProtectedResource(
            response.accessToken, httpTransport, jsonFactory, clientId,
            clientSecret, response.refreshToken);
    com.google.api.services.calendar.Calendar service = new com.google.api.services.calendar.Calendar.Builder(
            httpTransport, accessProtectedResource, jsonFactory).setApplicationName(
            "AppName").build();

任何形式的帮助都是感激的。

此错误可能是由于API控制台中配置错误。确保您的项目设置为"Installed Application"。

这个帖子可能有帮助。

相关内容

  • 没有找到相关文章

最新更新