GuzzleHttp的访问令牌为空

时间:2019-04-09 08:14:10

标签: php microsoft-graph guzzle guzzlehttp

当我尝试使用以下代码连接到Microsoft Graph时:

$headers = [
    'Authorization: Bearer ' . $this->getAccessToken(),
    'Content-Type: application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8',
    'Preference-Applied: odata.track-changes'
];
$response = $this->guzzle->request('GET', 'https://graph.microsoft.com/v1.0/me/calendarview/delta?startdatetime=2017-12-12T00:00:00Z&enddatetime=2020-12-13T00:00:00Z'. ['headers' => $headers], ['debug' => true]);

哪个给我错误: Access token is empty

调试给了我这个

  
      
  • 关于将connect()连接到graph.microsoft.com端口443(#0)
  •   
  • 尝试40.126.9.112 ...
  •   
  • 已连接到graph.microsoft.com(40.126.9.112)端口443(#0)
  •   
  • 使用证书路径初始化NSS:sql:/ etc / pki / nssdb
  •   
  • CAfile:/etc/pki/tls/certs/ca-bundle.crt CApath:无
  •   
  • 使用TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384的SSL连接
  •   
  • 服务器证书:
  •   
  • 主题:CN = graph.microsoft.com
  •   
  • 开始日期:2019年1月27日19:09:45 GMT
  •   
  • 到期日期:格林尼治标准时间2021年1月27日19:09:45
  •   
  • 通用名称:graph.microsoft.com
  •   
  • 发布者:CN = Microsoft IT TLS CA 2,OU = Microsoft IT,O = Microsoft Corporation,L = Redmond,ST =华盛顿,C = US      
        

    获取/v1.0/me/calendarview/delta?startdatetime=2017-12-12T00:00:00Z&enddatetime=2020-12-13T00:00:00ZArray     HTTP / 1.1用户代理:GuzzleHttp / 6.3.3 curl / 7.29.0 PHP / 5.6.40主机:     graph.microsoft.com

      
  •   
     

当我提供相同的详细信息时,它在Postman中确实可以工作,但是您可以看到Bearer之后的代码为空。我确实检查了$this->getAccessToken(),它肯定包含令牌。

我在这里做什么错了?

1 个答案:

答案 0 :(得分:3)

        $headers = [
        "Authorization" => "Bearer". $token,
        'Content-Type' => 'application/json'
    ];

$response = $this->guzzle->request('GET', 'https://graph.microsoft.com/v1.0/me/calendarview/delta?startdatetime=2017-12-12T00:00:00Z&enddatetime=2020-12-13T00:00:00Z', ['headers' => $headers], ['debug' => true]);

您在URL后面加了一个点,但需要一个逗号。另外,您的$ headers数组的格式应类似于“ $key => $values”关系,以便在枪口请求中传递。