如何对UpgradeableApp API进行身份验证,以将Google Apps Marketplace Apps从v1迁移到v2?

问题描述 投票:1回答:1

我们正在使用https://www.googleapis.com/appsmarket/v2/upgradableApp将oauth1.0应用迁移到oauth2.0应用。

我们指的是https://developers.google.com/apps-marketplace/v1migratev2

拨打电话时,我们收到“无效的OAuth标头”错误(401)

我们仅在使用消费者密钥和消费者秘密。 我们没有使用任何令牌。

我确信我们在这里缺少什么。 但不确定是什么。 任何指向此问题的指针都会对我们有所帮助。

提前致谢。

这是示例代码HttpClient client = new HttpClient(); PutMethod method = new PutMethod(" https://www.googleapis.com/appsmarket/v2/upgradableApp/ //"); method.addRequestHeader("Authorization", "oAuth"); method.addRequestHeader("Consumer Key",""); method.addRequestHeader("Consumer Key Secret",""); try { int status = client.executeMethod(method); System.out.println("status:" + status); System.out.println("response:" + method.getResponseBodyAsString()); } catch (HttpException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } HttpClient client = new HttpClient(); PutMethod method = new PutMethod(" https://www.googleapis.com/appsmarket/v2/upgradableApp/ //"); method.addRequestHeader("Authorization", "oAuth"); method.addRequestHeader("Consumer Key",""); method.addRequestHeader("Consumer Key Secret",""); try { int status = client.executeMethod(method); System.out.println("status:" + status); System.out.println("response:" + method.getResponseBodyAsString()); } catch (HttpException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }

结果:

状态::: 401响应:: {“错误”:{“错误”:[{“域”:“全局”,“原因”:“ authError”,“消息”:“无效的OAuth>标头”,“ locationType” :“ header”,“ location”:“ Authorization”}],“ code”:401,“ message”:“在有效的OAuth标头中”}}

google-apps-marketplace
1个回答
1
投票

我们使用针对Google的OAuth 1.0 API尝试了以下代码,并且工作正常。

OAuthRequest request = new OAuthRequest(Verb.PUT, api.getUpdateDomainEndpoint(listingId, chromeWSId, domain));
request.addOAuthParameter(OAuthConstants.TIMESTAMP, api.getTimestampService().getTimestampInSeconds());
request.addOAuthParameter(OAuthConstants.NONCE, api.getTimestampService().getNonce());
request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, config.getApiKey());
request.addOAuthParameter(OAuthConstants.SIGN_METHOD, api.getSignatureService().getSignatureMethod());
request.addOAuthParameter(OAuthConstants.VERSION, getVersion());
request.addOAuthParameter(OAuthConstants.SIGNATURE, getSignature(request, token));
String oauthHeader = api.getHeaderExtractor().extract(request);
request.addHeader(OAuthConstants.HEADER, oauthHeader);
© www.soinside.com 2019 - 2024. All rights reserved.