3

アプリに Google でのログインを追加しようとしています。ユーザーが Google にリダイレクトされて ( で) 返された後、codeアクセス トークンを取得する必要があります。

        $url = "https://accounts.google.com/o/oauth2/token";
        $content = "code={$code}&client_id={$params['appid']}&client_secret={$params['secret']}&" .
            "redirect_uri=$return_url&grant_type=authorization_code";

        $opts = array(
            'http'=>array(
                'method'=>'POST',
                'header'=>'Content-type: application/x-www-form-urlencoded\r\n' .
                    'Content-Length: ' . strlen($content)
            )
        );

        $cont = stream_context_create($opts);

        $response = file_get_contents($url + '?' + $content, false, $cont);

最後の行は警告をスローします[function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 411 Length Required。それでも、ご覧のとおり、Content-Lengthヘッダーをリクエストに入れました。誰かが何が間違っているのか教えてもらえますか?

前もって感謝します!

4

0 に答える 0