相关疑难解决方法(0)

java中的Google Analytics授权

我正在寻找以编程方式登录Google Analytics并获取数据的最简单方法.Google文档编写并提供了Oauth 2.0的示例,其中涉及用户手动登录其Google帐户,然后通过授权重定向到我的网站.但这不是我想要实现的 - 我正在构建一个自动工具,需要对用户/通行证或任何其他授权密钥进行硬编码,然后在没有任何用户参与的情况下登录(这是一个定期报告工具) .

我已经找到了一些关于API KEY的内容,但我找不到任何示例如何做到这一点,或者如何使用Google java库找到它.

我非常感谢指向正确的方向.这也许是其他人如何以最简单的方式做到这一点的有价值的线索 - 我认为记录应该很简单.

java authorization google-analytics

8
推荐指数
2
解决办法
8032
查看次数

使用服务帐户调用Java Google Drive Api时无效的授权

好!正如标题所述,我在使用服务帐户时遇到了一些严重的身份验证问题.所以,让我们从一开始就开始,因为我觉得我已经尝试了一切!

服务设置为:

在此输入图像描述

Drive SDK设置:

在此输入图像描述

服务帐户Api访问:

在此输入图像描述

如此处所述的Api客户端访问权限:http://support.google.com/a/bin/answer.py? hl = zh-CN&answer = 162106

在此输入图像描述

代码:

public static void callSpreadsheetApi() {

        GoogleCredential credential = null;
        try {
            credential = new GoogleCredential.Builder().setTransport(HTTP_TRANSPORT)
                    .setJsonFactory(JSON_FACTORY)                    
                    .setServiceAccountId("2363XXXXXX19.apps.googleusercontent.com")                    
                    .setServiceAccountScopes(DriveScopes.DRIVE, "https://spreadsheets.google.com/feeds", "https://docs.google.com/feeds")
                    .setServiceAccountPrivateKeyFromP12File(new File("/Users/stevesmith/Desktop/c02e064935d33c3389f6ab1dbf9ea747a5bdaac5-privatekey.p12"))
                    .setServiceAccountUser("steve.smith@reco.se")
                    .build();

        } catch (GeneralSecurityException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }


        Drive drive = new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).build();

        com.google.api.services.drive.model.File  file = new com.google.api.services.drive.model.File();
        file.setTitle("test");
        file.setMimeType("application/vnd.google-apps.spreadsheet");
        Drive.Files.Insert insert = null;
        try {
            insert = drive.files().insert(file);
            file = insert.execute();
        } …
Run Code Online (Sandbox Code Playgroud)

java google-api google-drive-api

5
推荐指数
1
解决办法
6158
查看次数