Google APIに接続しようとしました: failed to open stream: HTTP request failed! HTTP/1.0 401 Unauthorized
アクセストークンを要求してxxxを返しました。Google 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は私がjsonにリクエストして得た値です。
'$ 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-for-google-api) – hakre