【发布时间】:2020-02-23 17:18:14
【问题描述】:
$ret = file_get_contents('https://oauth2.googleapis.com/token', false, stream_context_create([
'http' => [
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'protocol_version' => 1.1,
'content' => http_build_query([
'client_id' => $client_id,
'client_secret' => $client_secret,
'refresh_token' => $refresh_token,
'grant_type' => $refresh_token
])
]
]));
运行脚本后,我看到 400 Bad Request 错误。我做错了什么?
【问题讨论】:
-
\r\n在标头值的末尾肯定看起来不合适。如果您以字符串形式传递 多个 标头,那么每个标头之间应该有一个 CR LF,但只有一个,我很确定这是错误的。 -
是的,那里仍然不需要他
标签: php oauth-2.0 google-api google-oauth