android - Google 日历 API 授权错误

标签 android google-api google-calendar-api

我是 Google Project 的新手,我必须在我的项目中集成 Google Calendar 和 Google Task。为此,我正在引用 [ https://developers.google.com/google-apps/calendar/instantiate][1] .我已经添加了:

google play services as library 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 控制台中的错误配置所致。确保您的项目设置为“已安装的应用程序”。

thread也许有帮助。

关于android - Google 日历 API 授权错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23539014/

相关文章:

android - 无法禁用 android.widget.Button

android - 是否可以向用户隐藏特定应用程序?

android - 如何从谷歌地图或地点 API 获取地点的图片

javascript - Google 日历 APi - JavaScript

google-calendar-api - Google 日历 API 批量插入已停止工作

java - Libgdx 处理 SVG

java - Android - 将触摸坐标发送到另一台设备

http - 在 REST URI 中包含 @me 这样的标记不会破坏 HTTP 缓存吗?

oauth - 所有这些字段是什么意思?

javascript - 函数 createEvent 返回 null