title: Android - Oauth2 - Server-side access for your app
body: <p>I've been having problems implementing Google Play Services login on my android app and passing the authorisation code to my backend server, so the server will exchange the code for access token and refresh token.</p>
  
  <p>First let me write a few lines what has already been tried/read:</p>
  
  <ul>
  <li>on code.google.com/apis/console I've created a new project, with two clients (WEB client and Android installed client)</li>
  <li>read articles on <a href="https://developers.google.com/+/mobile/android/sign-in#cross-platform_single_sign_on" rel="nofollow">https://developers.google.com/+/mobile/android/sign-in#cross-platform_single_sign_on</a> and <a href="http://android-developers.blogspot.com/2013/01/verifying-back-end-calls-from-android.html" rel="nofollow">http://android-developers.blogspot.com/2013/01/verifying-back-end-calls-from-android.html</a></li>
  </ul>
  
  <p>Next I wrote simple android app (based on Google Play Services sample auth app) and a simple python code using gdata (using web service client_id and secret).</p>
  
  <p>On android app I first used four scopes delimited with space and got a token. If I use this token in my python code I always get {'error_message': 'unauthorized_client'}.</p>
  
  <p>Then I tried to change the scope to this values and always got invalid scope error.</p>
  
  <ul>
  <li>oauth2:server:client_id:server-client-id:api_scope:scope1 scope2</li>
  <li>audience:server:client_id:server-client-id:api_scope:scope1 scope2</li>
  <li>oauth2:audience:server:client_id:server-client-id:api_scope:scope1 scope2</li>
  </ul>
  
  <p>For server-client-id I used the client_id of web server client, android client, other client</p>
  
  <p>Please can anyone help me with this problem.</p>
  
  <p>Thanx</p>
  
  <p>Here is the code for python backend</p>
  
  <pre><code>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__ 
  </code></pre>