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

查看:112
本文介绍了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


  • 还是我必须对两个gdata使用OAuth1和新的Google Java Client API?

  • 还是还有其他方法?

谢谢

推荐答案

我找到了解决方案。
您可以按照 http中记录的方式设置特殊的HTTP标头(授权:Bearer ACCESS_TOKEN) ://code.google.com/intl/zh-CN/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(例如这样的< a href = http://code.google.com/p/google-api-java-client/wiki/OAuth2Draft10> 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("\t" + 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天全站免登陆