Google Oauth-2.0使用哈希而不是问号返回网址

Dav*_*vid 4 google-analytics oauth-2.0

我使用此表单请求Google离线令牌

    <form action="https://accounts.google.com/o/oauth2/auth" methode="POST">

        <input type="hidden" name="access_type" value="offline" />
        <input type="hidden" name="client_id" value="XXX" />
        <input type="hidden" name="scope" value="https://www.googleapis.com/auth/analytics https://www.googleapis.com/auth/analytics.edit https://www.googleapis.com/auth/analytics.manage.users https://www.googleapis.com/auth/analytics.manage.users.readonly https://www.googleapis.com/auth/analytics.readonly" />
        <input type="hidden" name="response_type" value="code token gsession" />
        <input type="hidden" name="redirect_uri" value="http://example.com/analytics" />
        <input type="hidden" name="approval_prompt" value="force" />

        <button>Get or Refresh token</button>

    </form>
Run Code Online (Sandbox Code Playgroud)

谷歌怎么回信给我一个URL:

http://example.com/analytics#access_token=XXX&token_type=Bearer&expires_in=3600&code=YYY&authuser=0&num_sessions=1&prompt=consent&session_state=ZZZ
Run Code Online (Sandbox Code Playgroud)

请注意我们在主网址部分后面有一个哈希码#而不是问号?.

我期望用PHP获得上面的变量,$_GET但我不能因为那个哈希码.

我的问题是如何获得带问号的网址?

Han*_* Z. 7

您正在使用response_typecode token gsession触发所谓的Implicit流量,其中access_token将在网址片段被退回.response_type=code用于获取code值作为查询参数,您可以在令牌端点处使用该值来交换它,access_token如下所述:https://developers.google.com/accounts/docs/OAuth2WebServer#handlingtheresponse