我嘗試連接到谷歌的API,它返回: failed to open stream: HTTP request failed! HTTP/1.0 401 Unauthorized
我請求訪問令牌和它返回我的XXX,在那之後我用下面的PHP代碼連接到谷歌API:請求用戶的電子郵件返回未經授權的401錯誤
$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是我通過請求獲取的值。
'$ access_token'中有什麼? – hakre
[完整的OAuth示例](http://tools.ietf.org/html/rfc5849#section-1.2),[PHP Google API Oauth示例](http://stackoverflow.com/questions/2084087/oauth-with- PHP換谷歌-API) – hakre