如何使用Oauth v2在Fusion表中进行身份验证 [英] How to authenticate in Fusion tables with Oauth v2

查看:102
本文介绍了如何使用Oauth v2在Fusion表中进行身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从以下示例执行示例:

I'm trying to execute the example from:

https://code.google.com/p/google-api-java-client/source/browse?repo=samples#hg%2Ffusiontables-cmdline-sample

从本质上讲,这是一个有关如何认证和使用Fusion API的示例.我无法使其工作……在这一点上:

Which is basically an example on how to authenticate and use Fusion API. I can't make it work...at this point:

// authorize
return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");

浏览器显示错误:redirect_uri_mismatch".

The browser shows an "Error:redirect_uri_mismatch".

奇怪的是,其他使用Oauth进行身份验证的示例(google plus API和云存储),与本示例使用的方法不同,主要是使用可以下载一次的JSON文件已通过API控制台创建了服务帐户.

The weird thing here is that the other examples that authenticate using Oauth (google plus API and cloud storage one), don't use the same approach as this one, that basically consists in using the JSON file that you can download once a Service Account has been created trough the API console.

实际上,存在一个使用以下示例中的方法的问题:

Actually, there is a question that uses the approach from this examples:

Google Fusion Tables 400 invalid_grant

我的主要问题是..哪个是正确的?我不确定

My main question is..which one is correct? I'm not sure about this

第二个是...此示例在JSON文件中查找一个名为client-secret的项目,而我没有.我不认为这是导致代码无法使用的原因,但是我想知道这个客户端秘密问题是什么...

Second one is...this example looks for an item called client-secret in the JSON file, which I don't have. I don't think this is the cause that makes the code not workable, but I'm wondering what this client-secret thingy is...

对于如何进行的一些见解将不胜感激

Some insights on how to proceed would be greatly appreciated

谢谢! 亚历克斯

推荐答案

好吧,如果有人和我的情况一样……我将发布我认为有效的解决方案.我所做的基本上是对示例进行了修改(特别感谢Christian Junk的工作),因此在进行身份验证时,它看起来更像其他示例(存储和加号示例).

Well, if anyone is in the same situation as I was...I will post the solution I found to be working. What I did basically is modified the example (special thanks to Christian Junk for his work) so it looks more like the others examples (storage and plus ones) when it comes to authentication.

    HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();

    // check for valid setup
    if (SERVICE_ACCOUNT_EMAIL.startsWith("Enter ")) {
      System.err.println(SERVICE_ACCOUNT_EMAIL);
      System.exit(1);
    }
    String p12Content = Files.readFirstLine(new File("key.p12"), Charset.defaultCharset());
    if (p12Content.startsWith("Please")) {
      System.err.println(p12Content);
      System.exit(1);
    }
    // service account credential (uncomment setServiceAccountUser for domain-wide delegation)
    GoogleCredential credential = new GoogleCredential.Builder().setTransport(HTTP_TRANSPORT)
        .setJsonFactory(JSON_FACTORY)
        .setServiceAccountId(SERVICE_ACCOUNT_EMAIL)
        .setServiceAccountScopes(FusiontablesScopes.FUSIONTABLES)
        .setServiceAccountPrivateKeyFromP12File(new File("key.p12"))
        // .setServiceAccountUser("user@example.com")
        .build();


    // set up global FusionTables instance
    fusiontables = new Fusiontables.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME).build();

这与原始示例的方法不同,但是它对我有用,我可以列出表,创建新表,填充表并删除它们.

This differs from the approach of the original example, but it works for me and I could list the tables, create new ones, populate them and delete them.

我只是希望这些示例在Oauth和Fusion Tables文档页面中更容易找到,这将为我节省一些宝贵的时间:)

I just wish the examples were more easy to find in the Oauth and Fusion tables documentation pages, this would saved me some precious time :)

这篇关于如何使用Oauth v2在Fusion表中进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆