gpt4 book ai didi

Android - Oauth2 - 应用程序的服务器端访问

转载 作者:行者123 更新时间:2023-11-29 01:53:04 25 4
gpt4 key购买 nike

我在我的 Android 应用程序上实现 Google Play 服务登录并将授权代码传递到我的后端服务器时遇到问题,因此服务器将交换访问 token 和刷新 token 的代码。

首先让我写几行已经尝试/阅读的内容:

接下来我编写了简单的 android 应用程序(基于 Google Play 服务示例 auth 应用程序)和使用 gdata 的简单 python 代码(使用网络服务 client_id 和 secret)。

在 android 应用程序上,我首先使用了四个以空格分隔的范围并获得了一个 token 。如果我在我的 python 代码中使用这个标记,我总是得到 {'error_message': 'unauthorized_client'}。

然后我尝试将范围更改为此值,但总是出现无效范围错误。

  • oauth2:server:client_id:server-client-id:api_scope:scope1 scope2
  • 受众:服务器:客户端 ID:服务器客户端 ID:API_范围:范围 1 范围 2
  • oauth2:audience:server:client_id:server-client-id:api_scope:scope1 scope2

对于server-client-id我使用了web服务器客户端、android客户端、其他客户端的client_id

谁能帮我解决这个问题。

谢谢

这是python后端的代码

import gdata
import gdata.gauth


CLIENT_ID = 'client_id'
CLIENT_SECRET = 'secret_id'
SCOPES = ["https://www.google.com/m8/feeds", "https://mail.google.com", "https://www.googleapis.com/auth/userinfo.profile", "https://www.googleapis.com/auth/userinfo.email"]
USER_AGENT = 'my-app'

token = gdata.gauth.OAuth2Token(client_id=CLIENT_ID, client_secret=CLIENT_SECRET, scope=' '.join(SCOPES), user_agent=USER_AGENT)

print "token ", token
print token.generate_authorize_url(redirect_url='urn:ietf:wg:oauth:2.0:oob')

try:
print token.get_access_token("token")
except Exception, e:
print e
print e.__dict__

最佳答案

您正在检索授权代码,而不是访问 token 。这是两个不同的东西。

授权码 can be used in your server side to get an access token .它们不是访问 token ,不能这样使用。

关于Android - Oauth2 - 应用程序的服务器端访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16788732/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com