伙计们,我已经无计可施了!我正在try 访问共享文件夹,收到以下错误:

Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: 
`GET https://graph.microsoft.com/v1.0/shares/u!aHR0cHM6Ly8xZHJ2Lm1zL2Yvcy
FBdHVBTV9OYWN3VmFoaUZwdU1HU19CaVFDd1d1/root?expand=children` resulted in a 
`403 Forbidden` response: 

{"error":{"code":"accessDenied","message":"The 
    sharing link no longer exists, or you do not have permission to access 
    it."

,"innerError":{"date":"2023-10-11T05:01:49","request-id":"27bd1fc1-
74f8-4d8d-9a43-41a3aa6a9f02","client-request-id":"27bd1fc1-74f8-4d8d-9a43
-41a3aa6a9f02"}}}

分享来自这StackOverflow Question,如果你点击链接,它是非常可分享的,可以通过浏览器访问,所以does exist,所以这不是缺乏访问的问题,只是因为某种原因我的申请被拒绝了.

通常情况下,这将与没有正确的权限相关联,但令牌显示权限是access token的一部分,此处:

      "appid": "563e2470-8b86-48dc-9050-20228336584e",
  "appidacr": "1",
  "idp": "https://sts.windows.net/74162350-5947-4628-892f-4ee1d28d88cc/",
  "idtyp": "app",
  "oid": "d9b6b299-ddc2-4708-ac87-2a48beb896f4",
  "rh": "0.AUIAUCMWdEdZKEaJL07h0o2IzAMAAAAAAAAAwAAAAAAAAACkAAA.",
  "roles": [
    "Application.ReadWrite.All",
    "Sites.Read.All",
    "Application.Read.All"
  ],
  "sub": "d9b6b299-ddc2-4708-ac87-2a48beb896f4",
  "tenant_region_scope": "OC",
  "tid": "74162350-5947-4628-892f-4ee1d28d88cc",
  "uti": "rJQ_ra77J0ux9XBeCvMIAA",
  "ver": "1.0",
  "wids": [
    "0997a1d0-0d1d-4acb-b408-d5ca73121e90"
  ],

并且访问共享的代码段是(在->execute失败):

$guzzle = new \GuzzleHttp\Client();
$url = 'https://login.microsoftonline.com/' . $tenantId . '/oauth2/v2.0/token';
/*
* If the client requests scope=https://graph.microsoft.com/.default, no consent prompt is shown, regardless of the contents of the client application's registered permissions for Microsoft Graph. The returned token contains the scopes Mail.Read and User.Read.
*/
$token = json_decode($guzzle->post($url, [
    'form_params' => [
    'client_id' => $clientId,
    'scope' => 'https://graph.microsoft.com/.default',
    'grant_type' => 'client_credentials',
    'client_secret' => $clientSecret,
    ],
])->getBody()->getContents());
$accessToken = $token->access_token;

$graph = new Graph();
$graph->setAccessToken($accessToken);
$user = $graph->createRequest("GET", "/shares/u!aHR0cHM6Ly8xZHJ2Lm1zL2YvcyFBdHVBTV9OYWN3VmFoaUZwdU1HU19CaVFDd1d1/root?expand=children")
       ->setReturnType(Microsoft\Graph\Model\DriveItem::class)
       ->execute();

推荐答案

Note:根据MsDoc,要访问共享文件夹,必须向Azure AD应用程序授予101102 API应用程序权限.

授予100权限也会起作用.

我创造了一个Azure AD Application and granted API permissions,如下所示:

enter image description here

我通过postman 使用以下参数生成了access token:

https://login.microsoftonline.com/TenantID/oauth2/v2.0/token

client_id:ClientID
client_secret:ClientSecret
scope↵:https://graph.microsoft.com/.default
grant_type:client_credentials

enter image description here

当我解码访问令牌时,显示了roles个:

enter image description here

我共享了该文件夹并复制了共享URL,如下所示:

enter image description here

我对共享URL进行了编码:

string sharingUrl = "https://xxx.sharepoint.com/:f:/s/testruk/Eqh5o5j4qqNEqHjy4qK9-dgBoU61RnP3UNj0OVtpuUq0J*****";
string base64Value = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(sharingUrl));
string encodedUrl = "u!" + base64Value.TrimEnd('=').Replace('/', '_').Replace('+', '-');

Console.WriteLine(encodedUrl);

enter image description here

我try 使用以下查询访问共享文件夹,得到results successfully:

https://graph.microsoft.com/v1.0/shares/ShareID/root?expand=children

enter image description here

If still the issue persists,请判断以下各项:

  • try 创建新的Azure AD应用程序并生成访问令牌.
  • 确保您在请求中通过了correct encoded 100.
  • 确保共享链接存在,并且共享文件夹未被删除.

Reference:

Access Denied error when accessing a shared folder - SharePoint

Php相关问答推荐

自定义WooCommerce查询字符串仅显示前3个产品

管理员订单列表中的自定义列与WooCommerce 8.6.1一起消失

LaravelEloquent 的地方条件父/子与第三模型多对多

PHP-转义字符串内的双反斜杠

WooCommerce基于元数据的自定义范围目录排序

如何将对我的域的请求重定向到子文件夹中的索引,同时保留域URL并使用.htaccess?

致命错误:未捕获错误:Google\Auth\HttpHandler\HttpHandlerFactory::build()

在WooCommerce中禁用客户用户角色的纳税计算

Php解压缩deflate64

只收取WooCommerce中最高的运费

限制某些产品只能在WooCommerce的特定邮政编码/邮政编码范围内发货

限制联系人页面仅允许在WooCommerce中登录的用户

在特征中使用类的属性

WooCommerce 订单和邮箱通知的自定义产品描述

使用 PHP 的 OAuth 2.0 MAC

防止使用woocommerce_checkout_process下单

docker |管道失败的 ubuntu 源列表

为什么可以从 PHP 类访问 PHP Trait 的私有成员?

如何在 Laravel 9 中判断异常是否可报告?

路由未定义的 laravel 导出