如何解决Microsoft Graph javascript SDK从OneDrive获取文件内容
我正在尝试在基于React的Microsoft外接程序项目中获取文件的内容。 但是,当我调用getContentsOfFile()时,会收到一个GraphError,状态码为0,没有其他信息。 我知道正确的访问令牌,因为如果我调用“ me / drive / root:/Documents/SampleData.csv”,那么我会得到有效的响应。 我在这里想念什么?
import { ResponseType } from "@microsoft/microsoft-graph-client";
var graph = require('@microsoft/microsoft-graph-client');
function getAuthenticatedClient(accessToken: string) {
// Initialize Graph client
const client = graph.Client.init({
// Use the provided access token to authenticate
// requests
authProvider: (done: any) => {
done(null,accessToken);
}
});
return client;
}
export async function getContentsOfFile(itemId: string,accessToken: string) {
const client = getAuthenticatedClient(accessToken);
console.log(itemId);
const path = "/me/drive/items/" + itemId + "/content"
try {
const fileContents = await client.api(path).responseType(ResponseType.TEXT).get();
console.log(fileContents);
return fileContents;
} catch (error) {
console.log(error);
throw error;
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。