title: google oauth authentication
body: <p>i am trying to pass the authorization to then get data from google plus but the data variable keeps showing a value of "moved temporarily" what am i doing wrong? </p>
  
  <pre><code>&lt;?php
  session_start();
  
      $client_id = '';
      $client_secret = '';
      $api_key = '';
      $redirect_uri = 'http://localhost:8888/oauth';
      $scope = "https://www.googleapis.com/auth/plus.me";
  
      if (!isset($_REQUEST['code']))
      {
          $login_path = "https://accounts.google.com/o/oauth2/auth?";
          $login_path .= "redirect_uri=" . $redirect_uri;
          $login_path .= "&amp;response_type=code";
          $login_path .= "&amp;client_id=" . $client_id;
          $login_path .= "&amp;approval_prompt=force";
          $login_path .= "&amp;scope=" . $scope;
          $login_path .= "&amp;access_type=offline";
  
          echo "&lt;a href='" . $login_path . "'&gt;login&lt;/a&gt;";
      }
  
      else
      {
  
          $ch = curl_init();
  
          curl_setopt($ch, CURLOPT_URL, "https://accounts.google.com/o/oauth2/auth");
  
          curl_setopt($ch, CURLOPT_POST, TRUE);
  
          // This option is set to TRUE so that the response
          // doesnot get printed and is stored directly in
          // the variable
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  
          $post_params = "code=" . $_REQUEST['code'] . "&amp;";
          $post_params = "redirect_uri=" . $redirect_uri . "&amp;";
          $post_params .= "client_id=" . $client_id . "&amp;";
          $post_params .= "scope=" . $scope . "&amp;";
          $post_params .= "client_secret=" . $client_secret . "&amp;";
          $post_params .= "grant_type=authorization_code&amp;";
          $post_params .= "response_type=code";
  
  
          curl_setopt($ch, CURLOPT_POSTFIELDS, $post_params);
  
          $data = curl_exec($ch);
  
          curl_close($ch);
  
          //commented this since data was showing empty
          //$data = json_decode($data);
  
          print '&lt;pre&gt;';
          print $data;
          print '&lt;/pre&gt;';
  }
  </code></pre>