如何从Oauth1迁移到Oauth2?

如何从Oauth1迁移到Oauth2?,oauth,google-api,google-oauth,Oauth,Google Api,Google Oauth,我一直在遵循迁移教程中的步骤: 我正在发送一个正确的“身份验证”头,但我得到的只是: { "error" : "invalid_token" } Oauth令牌有效,我可以从我的应用程序访问GData服务 这是我的迁移代码(简化): com.google.gdata.client.authn.oauth.OAuthParameters OAuthParameters=new com.google.gdata.client.authn.oauth.OAuthParameters(); com.

我一直在遵循迁移教程中的步骤:

我正在发送一个正确的“身份验证”头,但我得到的只是:

{ "error" : "invalid_token" }
Oauth令牌有效,我可以从我的应用程序访问GData服务

这是我的迁移代码(简化):

com.google.gdata.client.authn.oauth.OAuthParameters OAuthParameters=new com.google.gdata.client.authn.oauth.OAuthParameters();
com.google.gdata.client.authn.oauth.oauthmacsha1signer=new com.google.gdata.client.authn.oauth.oauthmacsha1signer();
setOAuthConsumerKey(oauthConsumerKey);
setOAuthConsumerCret(OAuthConsumerCret);
setOAuthToken(account.getOAuthToken());
setOAuthTokenSecret(account.getOAuthTokenSecret());
OAuthHelper OAuthHelper=新的Google OAuthHelper(签名者);
字符串头=authHelper.getAuthorizationHeader(“http://www.sharedgroups.com“,”POST“,oauthParameters);
HTTPRequest请求=新HTTPRequest(新URL(“https://accounts.google.com/o/oauth2/token),HTTPMethod.POST);
字符串clientId=“.apps.googleusercontent.com”;
字符串clientSecret=“”;
String payload=“授权类型=urn%3Aietf%3Aparams%3Aoauth%3Agrant类型%3Amigration%3Aoauth1&client\u id=“+clientId+”&client\u secret=“+clientSecret;
addHeader(新的HTTPHeader(“授权”,header));
request.setPayload(payload.getBytes());
URLFetchService URLFetchService=URLFetchServiceFactory.getURLFetchService();
HTTPResponse response=urlFetchService.fetch(请求);
resp.getWriter().println(“RESPONSE=“+新字符串(RESPONSE.getContent()));

我们对OAuth1->OAuth2令牌迁移的验证部分做了一些更改。您介意再次检查迁移流并用结果更新此线程吗?

感谢您报告此问题。我正在研究这一点,将尽快更新此线程。
com.google.gdata.client.authn.oauth.OAuthParameters oauthParameters = new com.google.gdata.client.authn.oauth.OAuthParameters();
com.google.gdata.client.authn.oauth.OAuthHmacSha1Signer signer = new com.google.gdata.client.authn.oauth.OAuthHmacSha1Signer();
oauthParameters.setOAuthConsumerKey(oauthConsumerKey);
oauthParameters.setOAuthConsumerSecret(oauthConsumerSecret);
oauthParameters.setOAuthToken(account.getOAuthToken());
oauthParameters.setOAuthTokenSecret(account.getOAuthTokenSecret());
OAuthHelper oauthHelper = new GoogleOAuthHelper(signer);
String header = authHelper.getAuthorizationHeader("http://www.sharedgroups.com", "POST", oauthParameters);
HTTPRequest request = new HTTPRequest(new URL("https://accounts.google.com/o/oauth2/token"), HTTPMethod.POST);
String clientId = "<myid>.apps.googleusercontent.com";
String clientSecret = "<mysecret>";
String payload = "grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Amigration%3Aoauth1&client_id="+clientId+"&client_secret="+clientSecret;
request.addHeader(new HTTPHeader("Authorization", header));
request.setPayload(payload.getBytes());
URLFetchService urlFetchService = URLFetchServiceFactory.getURLFetchService();
HTTPResponse response = urlFetchService.fetch(request);
resp.getWriter().println("RESPONSE="+new String(response.getContent()));