title: Android - Google Sign-in on Web API - How to send Google Sign-in POST-request?
body: <p>I've got an Android project that allows me to <a href="http://www.androidhive.info/2014/02/android-login-with-google-plus-account-1/" rel="nofollow">log-in with Google-accounts</a>. Everything works as it's supposed to and I'm able to retrieve the Person's (<code>com.google.android.gsm.model.people.Person</code>) data, like Google email, username, profile picture url, etc.</p>
  
  <p>I also have a Web API hosted online. In this Web API I can get a JSON-list of products by using the following: <code>mywebhost/api/products</code>.</p>
  
  <p>Obviously these GET-requests are Authorized by OAuth 2.0, meaning I have to log-in with a Google Account on the <code>mywebhost/Account/Login</code> page to be authorized to get the JSON-list from the Web API. (When I'm not logged in, I receive the following JSON-list: <code>{"$id":"1","Message":"Authorization has been denied for this request."}</code>)</p>
  
  <p>I know how to send POST-requests in Android. For example with the code:</p>
  
  <pre><code>public class TaskPostAPI extends AsyncTask&lt;String, Void, String&gt;
  {   
      GoogleApiClient googleAPI;
  
      public TaskPostAPI(GoogleApiClient googleAPI){
          this.googleAPI = googleAPI;
      }
  
      @Override
      protected String doInBackground(String... urls){
          String response = "";
          for(String url : urls){
              DefaultHttpClient client = new DefaultHttpClient();
              HttpPost post = new HttpPost(url);
              try{
                  List&lt;NameValuePair&gt; nvPairs = new ArrayList&lt;NameValuePair&gt;(3);
                  //nvPairs.add(new BasicNameValuePair("personName", Plus.PeopleApi.getCurrentPerson(googleAPI).getDisplayName()));
                  //nvPairs.add(new BasicNameValuePair("personGooglePlusProfile", Plus.PeopleApi.getCurrentPerson(googleAPI).getUrl()));
                  //nvPairs.add(new BasicNameValuePair("personEmail", Plus.AccountApi.getAccountName(googleAPI)));
  
                  // TODO: Use the correct nvPairs to be able to Log-in with the Google-account
  
                  post.setEntity(new UrlEncodedFormEntity(nvPairs));
  
                  HttpResponse execute = client.execute(post);
                  InputStream content = execute.getEntity().getContent();
  
                  BufferedReader buffer = new BufferedReader(new InputStreamReader(content));
                  String s = "";
                  while((s = buffer.readLine()) != null)
                      response += s;
              }
              catch(Exception ex){
                  ex.printStackTrace();
              }
          }
          return response;
      }
  
      @Override
      protected void onPostExecute(String result){
          // Do nothing yet
      }
  }
  </code></pre>
  
  <p>So, now the question:</p>
  
  <ol>
  <li>In the code sample above, what should the nvPairs be to be able to successfully log-in with a Google-account. Or should I use something completely different than normal HttpPost to log-in with a Google-account on my Web API?</li>
  <li>Also: The url provided is the default Log-in page. On this page I have three different options to log-in. Since we only want to use the Google log-in, how can I retrieve the url of the Google Log-in button from the Web API Login-page to use for the POST-request?</li>
  </ol>
  
  <p>2b. With the second question: What Plug-in I could use in FireFox to see the links I'm redirected to? So I know which Login-url I should use instead of the default Login-page.</p>
  
  <p>Thanks in advance for the responses.</p>
  
  <hr>
  
  <p>Edit 1: I've tried a different approach, but I'm not sure it will work for the HttpGet-requests. What I've tried is opening a WebView with the Log-in page, and after I reach the page where I come when I successfully logged-in, I close the WebView.</p>
  
  <p>However, when I use the HttpGet-requests, I still get the Unauthorized JSON back, so how can I use this WebView Log-in to make the HttpGet-request "believe" I'm logged-in and Authorized?</p>
  
  <p>If someone still has an idea using the first approach (HttpPost-request), or if someone has a completely different approach, let me know.</p>