将AppIdentityCredential与Google Drive API结合使用 [英] Using AppIdentityCredential with Google Drive API

查看:197
本文介绍了将AppIdentityCredential与Google Drive API结合使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Google App Engine标识访问Google Apps用户的Google Drive API。
我在Google Apps中的管理API客户端访问中插入了GAE网址,并带有合适的范围。

  AppIdentityCredential凭证=新的AppIdentityCredential(Arrays.asList(DriveScopes.DRIVE_FILE)); 
HttpTransport httpTransport = new NetHttpTransport();
JsonFactory jsonFactory = new JacksonFactory();
Drive service =新的Drive.Builder(httpTransport,jsonFactory,凭证).build();

我得到这个错误:

  com.google.appengine.repackaged.org.apache.http.impl.client.DefaultRequestDirector handleResponse 
警告:身份验证错误:无法应对以下任何挑战:{authsub = WWW -Authenticate:AuthSub realm =https://www.google.com/accounts/AuthSubRequestallowed-scopes =https://www.googleapis.com/auth/drive,https://www.googleapis.com/ AUTH /文档,HTTPS://www.googleapis.com/auth/drive.file,https://www.googleapis.com/auth/drive.readonly,https://www.googleapis.com/auth/drive。 metadata.readonly}
发生错误:com.google.api.client.googleapis.json.GoogleJsonResponseException:401确定
{
code:401,
错误:[{
domain:global,
location:Authorization,
locationType:header,
message:Invalid凭证,
原因:authError
}],
消息:无效凭证
}




  • 是否有必要在Google Apps中的API客户端访问中启用GAE应用程序?如果不是,我如何授权GAE应用程序访问API范围?

  • 是否可以在本地/ Eclipse中测试GAE身份?

  • 总结,什么是错误或缺乏?


解决方案


  1. 您无法在本地调试AppEngine凭证。调试的唯一方法是使用不同的凭据(AppEngine用于生产,本地基于Key的服务帐户)。它需要为本地和生产环境编写不同的代码。


  2. 您需要将您的appengine服务帐户添加到Team。如果您为自己的项目使用自定义Google Apps域,则需要在自定义域中创建电子邮件组并添加此组。所有服务帐户都应该添加到这个组中。



I am using Google App Engine Identity to access Google Drive API of a Google Apps user. I have inserted GAE URL in Manage API client access in Google Apps, with the right scope.

AppIdentityCredential credential = new AppIdentityCredential(Arrays.asList(DriveScopes.DRIVE_FILE));
    HttpTransport httpTransport = new NetHttpTransport();
    JsonFactory jsonFactory = new JacksonFactory();
    Drive service = new Drive.Builder(httpTransport, jsonFactory, credential).build();

I get this error:

com.google.appengine.repackaged.org.apache.http.impl.client.DefaultRequestDirector handleResponse
WARNING: Authentication error: Unable to respond to any of these challenges: {authsub=WWW-Authenticate: AuthSub realm="https://www.google.com/accounts/AuthSubRequest" allowed-scopes="https://www.googleapis.com/auth/drive,https://www.googleapis.com/auth/docs,https://www.googleapis.com/auth/drive.file,https://www.googleapis.com/auth/drive.readonly,https://www.googleapis.com/auth/drive.metadata.readonly"}
An error occurred: com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 OK
{
  "code" : 401,
  "errors" : [ {
    "domain" : "global",
    "location" : "Authorization",
    "locationType" : "header",
    "message" : "Invalid Credentials",
    "reason" : "authError"
  } ],
  "message" : "Invalid Credentials"
}

  • Is it necessary to enable GAE application in API Client access in Google Apps? If not, how I authorise GAE app to gain acess to an API Scope?
  • Is possible to test GAE Identity in Local / Eclipse?
  • Summarizing, what is wrong or lack?

解决方案

  1. You can not debug AppEngine Credentials locally. The only way to debug is to use different credentials (AppEngine for production and Key-based service account locally). It will require to write different code for local and production environment.

  2. You need to add your appengine service accounts to Team. If you use custom Google Apps domain for your project than you will need to create email group in your custom domain and add this group. All service accounts should be added to this group.

这篇关于将AppIdentityCredential与Google Drive API结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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