如何检查一个驱动器访问令牌是否处于活动状态?我下面的代码不起作用:(需要帮助!
function check_one_drive_active(access_token){
var od_api_root_url = "https://api.onedrive.com/v1.0/drive/root/";
var od_url_param = "?access_token="+access_token;
var od_api_url = od_api_root_url+od_url_param;
alert(od_api_url);
jQuery.ajax({
url: od_api_url,
dataType : "JSON",
type : "POST",
success: function(data){
alert(data.error.code);
}
});
}
相反,您可以使用
/me/drive
端点,这是用于检索有关用户驱动器的信息的常见端点,并且还在 ajax 请求的请求标头中包含访问令牌。
function check_one_drive_active(access_token) {
var od_api_root_url = "https://graph.microsoft.com/v1.0/me/drive";
var od_api_url = od_api_root_url;
jQuery.ajax({
url: od_api_url,
headers: {
'Authorization': 'Bearer ' + access_token
},
type: "GET",
success: function(data) {
console.log("OneDrive access token is active");
console.log(data); // You can log or process the response data here
},
error: function(xhr, status, error) {
console.error("Error checking OneDrive access token:", status, error);
console.error(xhr.responseText);
// Handle error or token expiration here
}
});
}
// Example usage:
// Replace 'YOUR_ACCESS_TOKEN' with the actual OneDrive access token
check_one_drive_active('YOUR_ACCESS_TOKEN');