请求OAuth凭据时,我可以将access_type指定为脱机或联机.
选择在线访问类型会强制用户在每次登录时批准对我的应用程序的访问.这是为什么?用户尚未批准我的应用程序吗?
更新#1:
我将approval_prompt设置为'auto'.
如果我只是在不删除任何Cookie的情况下退出Google,则不会再次提示我.但删除cookie会带回授权屏幕.
更新#2:
它通过OAuth Playground运行良好. http://code.google.com/oauthplayground/
将OAuth 2.0用于Web服务器应用程序 https://developers.google.com/accounts/docs/OAuth2WebServer
更新#3: 相关代码段
Helper方法生成OAuth URL
def build_auth_uri
return @client.authorization.authorization_uri(
:access_type => :online,
:approval_prompt => :auto
).to_s
end
Run Code Online (Sandbox Code Playgroud)
在视图中调用Helper方法
<a href="<%= build_auth_uri %>"> Connect Me! </a>
Run Code Online (Sandbox Code Playgroud)
在网页上生成OAuth网址
https://accounts.google.com/o/oauth2/auth?access_type=online&approval_prompt=auto&redirect_uri=http://localhost:3000/gclient/gcallback&response_type=code
Run Code Online (Sandbox Code Playgroud)