简体   繁体   English

如何使用图形 api 访问 sharepoint 文件夹

[英]how to access sharepoint folder using graph api

In my SharePoint site Document Library, I have a folder called OneDriveInventory and I have a few file inside.在我的 SharePoint 站点文档库中,我有一个名为 OneDriveInventory 的文件夹,里面有一些文件。

I'm trying to access those file but it look like my Uri request is wrong so I would be really appreciated I can get any help or suggestion on how to fix this.我正在尝试访问这些文件,但看起来我的 Uri 请求是错误的,所以我将不胜感激,因为我可以获得有关如何解决此问题的任何帮助或建议。

 Invoke-WebRequest -Uri "https://graph.microsoft.com/v1.0/sites/$siteId/drives/$driveId/OneDriveInventory/$($filename)" -Method GET -OutFile $filePath -Headers $headers

I tried to reproduce the same in my environment and got below results:我试图在我的环境中重现相同的结果并得到以下结果:

I have one SharePoint document library in which I created folder named OneDriveInventory and added files like below:我有一个 SharePoint 文档库,我在其中创建了名为OneDriveInventory文件夹并添加了如下文件

在此处输入图像描述

You can make use of below Graph API call to access file in the above folder:您可以使用下面的Graph API 调用来访问上述文件夹中的文件:

GET https://graph.microsoft.com/v1.0/sites/<siteID>/drives/<driveID>/root:/OneDriveInventory:/children/<filename>

When I ran the above query in Graph Explorer , I got results successfully like below:当我在Graph Explorer中运行上述查询时,我成功地得到了如下结果

在此处输入图像描述

To get the same results from PowerShell, I registered one Azure AD application and added API permissions like below:为了从 PowerShell 获得相同的结果,我注册了一个 Azure AD 应用程序并添加了API 权限,如下所示:

在此处输入图像描述

Now I generated access token using below PowerShell script:现在我使用下面的 PowerShell 脚本生成了访问令牌

$tenantId = <tenantID>
$applicationId = <appID>
$secret= <secret>
$param = @{
        Uri = "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token";
        Method = 'Post';
        Body = @{ 
            grant_type = 'client_credentials'; 
            scope = 'https://graph.microsoft.com/.default'; 
            client_id = $applicationId; 
            client_secret = $secret
        }
   }
$result = Invoke-RestMethod @param
$token = $result.access_token

Response:回复:

在此处输入图像描述

To access file from folder, I used below PowerShell script:要从文件夹访问文件,我使用了以下 PowerShell 脚本:

$siteID = "3b23b598-f5e4-461f-b038-xxxxxx"
$driveID = "xxxxxxxxxxxxxxxxxxx"
$filename = "sridevi.txt"

$headers=@{}
$headers.Add("Content-Type", "text/plain")
$headers.Add("Authorization", "Bearer $token")
$response=Invoke-WebRequest -Uri "https://graph.microsoft.com/v1.0/sites/$siteID/drives/$driveID/root:/OneDriveInventory:/children/$($filename)" -Method GET -OutFile $filePath -Headers $headers

Response:回复:

在此处输入图像描述

When I ran $response.Content , I got full response like below:当我运行$response.Content时,我得到了如下的完整响应

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SharePoint 在 Powershell 中创建带有图形 api 的文件夹 - SharePoint create Folder with Graph api in Powershell 使用 Microsoft Graph 在线上传文件到 SharePoint API - Uploading a File to SharePoint Online using Microsoft Graph API 使用图形 API 将大文件上传到 SharePoint Online - ContentType 错误 - Upload large file to SharePoint Online using Graph API - ContentType error SharePoint 使用 MS Graph 进行大型上传 API - 第二块出错 - SharePoint Large Upload using MS Graph API - Erroring on second chunk 如何使用 PowerShell 将文件夹从本地驱动器移动到 Sharepoint 文件夹? - How to move folder from local drive to Sharepoint folder using PowerShell? 尝试使用 powershell 访问 sharepoint 在线列表 REST API 时出错 - Error trying to access the sharepoint online list REST API using powershell 使用带有 Windows 身份验证的 powershell 访问共享点 REST api - access sharepoint REST api using powershell with windows authentication 在 Azure 函数中使用托管标识来访问图形 API - Using Managed Identity in a Azure Function to access Graph API 如何使用Web服务访问Sharepoint中的子站点列表? - How to access lists of a sub-site in Sharepoint using web services? 使用Powershell授予对Sharepoint库中文件夹的权限? - Grant permissions to folder in Sharepoint library using Powershell?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM