【问题标题】:Google API - OAuth 2.0 - trying to get AccessToken using curlGoogle API - OAuth 2.0 - 尝试使用 curl 获取 AccessToken
【发布时间】:2020-09-10 02:36:23
【问题描述】:

尝试使用 curl 获取 AccessToken 但出现错误 “https://accounts.google.com/o/oauth2/token:没有这样的文件或目录” 有人可以帮助我做错什么吗?

主要是想知道我是否正确设置了客户端密码,虽然我很不确定,但非常感谢一些指导。

(已用*编辑了部分内容)

curl \
—request POST \
--data ”code=4/***********************3Uzp--0jT4uNN******rSWSRkHw8&client_id=***************************.apps.googleusercontent.com&client_secret=**********&redirect_uri=https://localhost&grant_type=authorization_code” \https://accounts.google.com/o/oauth2/token

【问题讨论】:

    标签: curl google-api google-oauth omniauth-google-oauth2


    【解决方案1】:

    这是我使用的代码。

    # Client id from Google Developer console
    # Client Secret from Google Developer console
    # Scope this is a space seprated list of the scopes of access you are requesting.
    
    # Authorization link.  Place this in a browser and copy the code that is returned after you accept the scopes.
    https://accounts.google.com/o/oauth2/auth?client_id=[Application Client Id]&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=[Scopes]&response_type=code
    
    # Exchange Authorization code for an access token and a refresh token.
    
    curl \
    --request POST \
    --data "code=[Authentcation code from authorization link]&client_id=[Application Client Id]&client_secret=[Application Client Secret]&redirect_uri=urn:ietf:wg:oauth:2.0:oob&grant_type=authorization_code" \
    https://accounts.google.com/o/oauth2/token
    
    # Exchange a refresh token for a new access token.
    curl \
    --request POST \
    --data 'client_id=[Application Client Id]&client_secret=[Application Client Secret]&refresh_token=[Refresh token granted by second step]&grant_type=refresh_token' \
    https://accounts.google.com/o/oauth2/token
    

    从我的一个要点GoogleAuthenticationCurl.sh 中提取的代码

    【讨论】:

    • 谢谢,我得到了访问令牌。
    • 您的回答是正确的,正是我想要的,再次感谢您。
    猜你喜欢
    • 1970-01-01
    • 2012-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-11
    相关资源
    最近更新 更多