gdata-java-client + oauth2 + access_token 秘密 [英] gdata-java-client + oauth2 + access_token secret

查看:35
本文介绍了gdata-java-client + oauth2 + access_token 秘密的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试使用新的 java 客户端,由于 google 库当前状态的遗留原因,我需要同时使用 gdata 和新的 google java 客户端 api.

I'm currently trying to use the new java client(s) and due to legacy reasons for current state of google libraries, I need to use both the gdata and the new google java client api.

显然我想使用 OAuth2——但是使用 OAuth2 我没有得到访问令牌的秘密——这会导致一个问题 b/c gdata 需要访问令牌的秘密.

Obviously I'd like to use OAuth2 -- however with OAuth2 I am not getting the access token secret -- which causes an issue b/c gdata requires the access token secret.

有人可以就解决方法提出建议,例如.- 有没有办法只使用访问令牌(OAuth2)而不是访问令牌秘密来使用 gdata java 库?代码示例(和尝试)不能证实这一点,但也许我做错了

Could anyone pls advise on a workaround eg. - is there a way to use gdata java libraries with only access token(OAuth2) and not access token secret? Code examples(and attempt) do not corroborate this but perhaps I'm doing something incorrectly

  • 还是我必须将 OAuth1 用于 gdata 和新的 google java 客户端 api?
  • 或者有其他方法吗?

谢谢

推荐答案

我找到了解决方案.您可以按照 http://code 中所述设置特殊的 HTTP 标头(授权:Bearer ACCESS_TOKEN).google.com/apis/accounts/docs/OAuth2WebServer.html#callinganapi

I found a solution. You can set a special HTTP-Header (Authorization: Bearer ACCESS_TOKEN) as documented in http://code.google.com/apis/accounts/docs/OAuth2WebServer.html#callinganapi

一旦您收到您的 accessToken(例如像这样 http://code.google.com/p/google-api-java-client/wiki/OAuth2Draft10 )您可以像这样调用旧"gdata 服务:

Once you have received your accessToken (e.g. like this http://code.google.com/p/google-api-java-client/wiki/OAuth2Draft10 ) you can call your "old" gdata service like this:

SpreadsheetService service = new SpreadsheetService("yourAppName");
service.setHeader("Authorization", "Bearer " + accessToken);
URL metafeedUrl = new URL("https://spreadsheets.google.com/feeds/spreadsheets/private/full");
SpreadsheetFeed feed = service.getFeed(metafeedUrl, SpreadsheetFeed.class);

List<SpreadsheetEntry> spreadsheets = feed.getEntries();
for (int i = 0; i < spreadsheets.size(); i++) {
  SpreadsheetEntry entry = spreadsheets.get(i);
  System.out.println("	" + entry.getTitle().getPlainText());
}

有点奇怪,我找不到它真正清楚地记录下来.我只是偶然发现的.

It's a bit odd that I couldn't find it really documented clearly. I just found it by coincidence.

这篇关于gdata-java-client + oauth2 + access_token 秘密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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