![](/img/trans.png)
[英]How to make OAuth2 Authorization Request via POST to Custom API using Scribe
[英]How to make a POST call using Scribe and fetch data having OAuth 1.0 Authentication in Java?
我需要對具有 OAuth 1.0 身份驗證的 URL 進行后調用。 我對所有這些都很陌生。 通過我的研究,我在 Java 中了解了 Scribe,但我只能找到使用 Scribe 的 Get 調用。 我已經有用於 OAuth 1.0 身份驗證的 consumerKey 和 consumerSecret 密鑰。 有沒有關於如何成功實現這一目標的建議。
使用 postman 我能夠成功獲取數據,但我想使用 Java 來實現它。
我嘗試過這樣的事情
我試過這種方式
public String getSmartCommPDF(@RequestBody Model model) throws IOException {
OAuthService service = new ServiceBuilder().provider(ModelAPI.class).apiKey(consumerKey)
.apiSecret(consumerSecret).build();
OAuthRequest request = new OAuthRequest(Verb.POST, url);
ObjectMapper mapper = new ObjectMapper();
request.addHeader("Content-Type", "application/json;charset=UTF-8");
request.addPayload(mapper.writeValueAsString(model));
Token accessToken = new Token("", ""); // not required for context.io
service.signRequest(accessToken, request);
Response response = request.send();
System.out.println("Response = " + response.getBody());
return "Success";
}
這是我的 ModelAPI class
public class ModelAPI extends DefaultApi10a {
@Override
public String getRequestTokenEndpoint() {
return "https://domain/one/oauth1/api/v6/job";
}
@Override
public String getAccessTokenEndpoint() {
return "https://domain/one/oauth1/api/v6/job";
}
@Override
public String getAuthorizationUrl(Token requestToken) {
return "https://domain/one/oauth1/api/v6/job";
}
}
這部分代碼沒有拋出任何錯誤,但是響應正文為空。 我哪里出錯了,有人知道嗎?
謝謝你。
數據在輸入 stream 中返回。 所以,我用
response.getStream();
並將其寫入文件並使用它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.