[英]Access token is empty with GuzzleHttp
When I try to make a connection to Microsoft Graph with the following code: 当我尝试使用以下代码建立与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]);
Which gives me the error: Access token is empty
这给了我错误:
Access token is empty
And the debug gives me this: 调试给了我这个:
- About to connect() to graph.microsoft.com port 443 (#0)
即将connect()连接到graph.microsoft.com端口443(#0)
- Trying 40.126.9.112...
尝试40.126.9.112 ......
- Connected to graph.microsoft.com (40.126.9.112) port 443 (#0)
连接到graph.microsoft.com(40.126.9.112)端口443(#0)
- Initializing NSS with certpath: sql:/etc/pki/nssdb
使用certpath初始化NSS:sql:/ etc / pki / nssdb
- CAfile: /etc/pki/tls/certs/ca-bundle.crt CApath: none
CAfile:/etc/pki/tls/certs/ca-bundle.crt CApath:none
- SSL connection using TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
使用TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384进行SSL连接
- Server certificate:
服务器证书:
- subject: CN=graph.microsoft.com
主题:CN = graph.microsoft.com
- start date: Jan 27 19:09:45 2019 GMT
开课日期:1月27日19:09:45 GM9 GMT
- expire date: Jan 27 19:09:45 2021 GMT
到期日:1月27日19:09:45 2021 GMT
- common name: graph.microsoft.com
通用名称:graph.microsoft.com
- issuer: CN=Microsoft IT TLS CA 2,OU=Microsoft IT,O=Microsoft Corporation,L=Redmond,ST=Washington,C=US
发行人:CN = Microsoft IT TLS CA 2,OU = Microsoft IT,O = Microsoft Corporation,L = Redmond,ST = Washington,C = US
GET /v1.0/me/calendarview/delta?startdatetime=2017-12-12T00:00:00Z&enddatetime=2020-12-13T00:00:00ZArray HTTP/1.1 User-Agent: GuzzleHttp/6.3.3 curl/7.29.0 PHP/5.6.40 Host: graph.microsoft.com
GET /v1.0/me/calendarview/delta?startdatetime=2017-12-12T00:00:00Z&enddatetime=2020-12-13T00:00:00ZArray HTTP / 1.1 User-Agent:GuzzleHttp / 6.3.3 curl / 7.29.0 PHP / 5.6.40主机:graph.microsoft.com
< HTTP/1.1 401 Unauthorized < Content-Type: application/json;
<HTTP / 1.1 401 Unauthorized <Content-Type:application / json; charset=utf-8 < request-id: c82bfd7f-921f-40b7-a973-38b6630cb2c2 < client-request-id: c82bfd7f-921f-40b7-a973-38b6630cb2c2 < x-ms-ags-diagnostic: {"ServerInfo":{"DataCenter":"West Europe","Slice":"SliceC","Ring":"5","ScaleUnit":"002","RoleInstance":"AGSFE_IN_45","ADSiteName":"WEU"}} < WWW-Authenticate: Bearer realm="", authorization_uri="https://login.microsoftonline.com/common/oauth2/authorize", client_id="00000003-0000-0000-c000-000000000000" < Strict-Transport-Security: max-age=31536000 < Date: Tue, 09 Apr 2019 08:08:39 GMT < Content-Length: 234
charset = utf-8 <request-id:c82bfd7f-921f-40b7-a973-38b6630cb2c2 <client-request-id:c82bfd7f-921f-40b7-a973-38b6630cb2c2 <x-ms-ags-diagnostic:{“ServerInfo”:{ “DataCenter”:“West Europe”,“Slice”:“SliceC”,“Ring”:“5”,“ScaleUnit”:“002”,“RoleInstance”:“AGSFE_IN_45”,“ADSiteName”:“WEU”}} <WWW-Authenticate:Bearer realm =“”,authorization_uri =“https://login.microsoftonline.com/common/oauth2/authorize”,client_id =“00000003-0000-0000-c000-000000000000”<Strict-Transport-Security :max-age = 31536000 <Date:Tue,09 Apr 201 08:08:39 GMT <Content-Length:234
Somehow it does work in Postman when I give the same details however like you can see, the code after Bearer
is empty. 不知何故,当我给出相同的细节时,它确实可以在Postman中工作,但是你可以看到,
Bearer
之后的代码是空的。 I did check $this->getAccessToken()
and it definitely contains the token. 我确实检查了
$this->getAccessToken()
,它肯定包含令牌。
What am I doing wrong here? 我在这做错了什么?
$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]);
You had a dot after your URL instead you needed a comma. 你的网址后面有一个点而不是你需要一个逗号。 Also your $
headers
array should be format like " $key => $values
" relation to be passed in the guzzle request. 你的$
headers
数组也应该像guzzle请求中传递的格式“ $key => $values
”关系一样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.