[英]Get token for Microsoft Graph API in Java
我想使用 Microsoft Graph API 來管理 Drive 文件,但我在身份驗證方面遇到了一些麻煩...
我有下面的代碼來獲得訪問我的帳戶的權限:
try(InputStream propFile = MicrosoftEngine.class.getClassLoader().getResourceAsStream("microsoft.properties")){
Properties prop = new Properties();
prop.load(propFile);
setGraphClient(GraphServiceClient.builder().authenticationProvider(request -> {
// Add the access token in the Authorization header
request.addHeader("Authorization", "Bearer " + prop.getProperty("token"));
}).buildClient());
IDriveItemCollectionPage children = graphClient.me().drive().root().children().buildRequest().get();
setDrive(children);
}
catch(IOException e) {
e.printStackTrace();
}
但目前,“token”屬性的值取自 Microsoft Graph Explorer :
一段時間后(可能是一個小時),令牌過期,我需要通過 Graph Explorer 發送另一個請求以獲得新令牌並將其復制/粘貼到我的 Java 代碼中。
但這並不方便...如何在 Java 中獲取此令牌值? 有任何想法嗎 ?
在此先感謝您的幫助 :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.