Closed ahernandez-iusup closed 2 weeks ago
If you want to share your code, we can try to help but generally "Access denied" implies you don't have access. Which either means you don't have a valid access token (i.e. since you're using node, I assume you have an app registration that grants the proper scopes) or you don't have delegated access to the thing you're trying to access. I have no way of helping you without further information.
const graph = graphfi().using(GraphDefault({
baseUrl: 'https://graph.microsoft.com/v1.0',
msal: {
config: configuration,
scopes: ['https://graph.microsoft.com/.default']
}
}));
graphMe.on.auth(async function (url, init) {
init.headers["Authorization"] = `Bearer ${token}`;
return [url, init];
});
//const files1 = await graph3.drives.getById(idDriveSharepoint).recent.orderBy("lastModifiedDateTime", false).top(5)()
const drives= await graphMe.drives()
const files = await graphMe.drives.getById(drives[0].id).recent.orderBy("lastModifiedDateTime", false).top(5)()
Files1 returns this, "code":"accessDenied","message":"The current caller is not the drive owner."
Files returns the top 5
Is there any way to get the recent files from sharepoint?
Hi. your code is not full and is unclear.
You've instantiated the graphfi object called graph
, then you are using a graphMe
object. Then on files1, you're using an object called graph3
Where did graphMe
and graph3
come from and how are they instantiated?
Where did that token come from that you are assigning to it in that behavior?
Can you share what permissions you've granted to your application in Azure?
Recent by design only works with a signed in user. The collection represents the set of recent files for that user, there isn't a concept of recent files in the drive. You could sort on last modified and use $top
Thanks for your help. As I understand it, using Recent I can't access a SharePoint drive. Is there a way to get recent files from a SharePoint library?
In graph a drive
is a SharePoint library or OneDrive... there is no difference.
/ Closing this issue as answered. If you have additional questions or we did not answer your question, please open a new issue, ref this issue, and provide any additional details available. Thank you!
This issue is locked for inactivity or age. If you have a related issue please open a new issue and reference this one. Closed issues are not tracked.
What version of PnPjs library you are using
4.x
Minor Version Number
1
Target environment
All
Additional environment details
I'm using Node.js to develop with PNP. I want to get the last 5/10 recent files that a user have seen or modified but I don't find a way to do it.
Question/Request
I have seen this: https://pnp.github.io/pnpjs/graph/files/#get-the-recent-files But when I try to use the drive id of my sharepoint it says: "code":"accessDenied","message":"The current caller is not the drive owner."
Is there a way how I can get the recent files from Sharepoint?