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

时间:2013-05-28 09:39:56

标签: android google-oauth

我在Android应用上实施Google Play服务登录时遇到问题,并将授权码传递给我的后端服务器,因此服务器会交换代码以获取访问令牌和刷新令牌。

首先让我写几行已经尝试过的内容:

接下来,我使用gdata编写了一个简单的Android应用程序(基于Google Play Services示例auth应用程序)和一个简单的python代码(使用Web服务client_id和秘密)。

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

然后我尝试将范围更改为此值,并始终得到无效的范围错误。

  • oauth2:server:client_id:server-client-id:api_scope:scope1 scope2
  • audience:server:client_id:server-client-id:api_scope:scope1 scope2
  • oauth2:audience:server:client_id:server-client-id:api_scope:scope1 scope2

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

任何人都可以帮我解决这个问题。

感谢名单

这是python backend的代码

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__ 

1 个答案:

答案 0 :(得分:1)

您正在检索授权代码,而不是访问令牌。这是两件不同的事情。

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

相关问题