【发布时间】:2011-09-27 08:33:51
【问题描述】:
我尝试连接到 google API 并返回:
failed to open stream: HTTP request failed! HTTP/1.0 401 Unauthorized
我请求了访问令牌,它返回给我 xxx,之后我通过以下 PHP 代码连接到 Google API:
$opts = array('http' =>
array(
'method' => 'GET',
'header' => "Authorization: OAuth $access_token\r\nContent-Type: application/json\r\n",
)
);
$context = stream_context_create($opts);
$result = file_get_contents('https://www.googleapis.com/userinfo/email?alt=json',false,$context);
我在哪里写错了标题或其他内容? 更新:$access_token 是我通过请求在 json 中获得的值。
【问题讨论】:
标签: php http-headers file-get-contents oauth-2.0