如何在Microsoft的PHP图形API中访问响应数据

问题描述 投票:0回答:1

我正在使用Microsoft的图形API将文件上传到onedrive。如果上传成功,我想删除本地文件。我的代码如下:

    public function testMoveFile()
    {    
        $graph = new Graph();
        $graph->setAccessToken($acccess_token);

        $response = $graph->createRequest("PUT", "/drives/$drive_id/items/root:/$filename:/content")
            ->attachBody($content)
            ->execute();

        if ($response->getStatusCode() > 201) {
            var_dump($response);
        } else {
            // remove the file
        }
    }

问题是,响应http状态代码似乎没有获取方法。当我使用var_dump()检查$response时,可以看到有一个名为_httpStatusCode的私有属性,但是当我尝试访问它时,由于它是私有的,因此会出现错误。当我浏览单元测试时,没有看到任何检查。还有另一种方法吗?

php microsoft-graph onedrive guzzle microsoft-graph-sdks
1个回答
0
投票

这比我想的要容易。要获取状态码,您必须

        if ($response->getStatus() > 201) {
© www.soinside.com 2019 - 2024. All rights reserved.