title: google analytics api need exact date, hour and minute
body: <p>Im experimenting with the google reports api (v4), im using the goalCompletionsAll metric, and is bringing the info that i need, im passing as parameters ga:medium, ga:date, ga:hour however when i pass the ga:minute parameter as request it throws me the following error: "Selected dimensions and metrics cannot be queried together." I understand that the metrics have their own set of dimensions, but i found this weird, since when i use the query explorer i add all this dimensions and it returns the correct info, but as soon as i put in the code, it displays the error...</p>
  
  <p><a href="https://i.stack.imgur.com/b5LRI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/b5LRI.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/pwUGU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pwUGU.png" alt="enter image description here"></a></p>
  
  <p>Here i attach my code to see if someone can point me into the right direction regarding this.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
  require_once 'google-api-php-client/src/Google/autoload.php';
  
  session_start();
  
  $client = new Google_Client();
  $client-&gt;setAuthConfigFile('xxxxx');
  $client-&gt;addScope(Google_Service_Analytics::ANALYTICS_READONLY);
  
  
  // If the user has already authorized this app then get an access token
  // else redirect to ask the user to authorize access to Google Analytics.
  if (isset($_SESSION['access_token']) &amp;&amp; $_SESSION['access_token']) {
    // Set the access token on the client.
    $client-&gt;setAccessToken($_SESSION['access_token']);
  
    // Create an authorized analytics service object.
    $analytics = new Google_Service_AnalyticsReporting($client);
  
    // Call the Analytics Reporting API V4.
    $response = getReport($analytics);
  
    // Print the response.
    printResults($response);
  
  } else {
    $redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . '/api/oauth2callback.php';
    header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
  }
  
  
  function getReport(&amp;$analytics) {
  
    // Replace with your view ID. E.g., XXXX.
    $VIEW_ID = "xxxxxxxx";
  
    // Create the DateRange object.
    $dateRange = new Google_Service_AnalyticsReporting_DateRange();
    $dateRange-&gt;setStartDate("2016-01-01");
    $dateRange-&gt;setEndDate("today");
  
    // Create the Metrics object.
    $sessions = new Google_Service_AnalyticsReporting_Metric();
    $sessions-&gt;setExpression("ga:goalCompletionsAll");
    $sessions-&gt;setAlias("objetivos");
    
    //Create the Dimensions object.
    $medium = new Google_Service_Analyticsreporting_Dimension();
    $medium-&gt;setName("ga:medium");
    
    $minute = new Google_Service_Analyticsreporting_Dimension();
    $minute-&gt;setName("ga:minute");
    
    $hour = new Google_Service_Analyticsreporting_Dimension();
    $hour-&gt;setName("ga:hour");
  
    $date = new Google_Service_Analyticsreporting_Dimension();
    $date-&gt;setName("ga:date");
  
    $avgpageloadtime = new Google_Service_Analyticsreporting_Metric();
    $avgpageloadtime-&gt;setExpression("ga:avgpageloadtime");
    $avgpageloadtime-&gt;setAlias("average load time");
  
    $goals = new Google_Service_Analyticsreporting_Metric();
    $goals-&gt;setExpression("ga:goalStartsAll");
  
    // Create the ReportRequest object.
    $request = new Google_Service_AnalyticsReporting_ReportRequest();
    $request-&gt;setViewId($VIEW_ID);
    $request-&gt;setDateRanges($dateRange);
    $request-&gt;setDimensions(array($medium, $date, $hour, $minute));
    $request-&gt;setMetrics(array($sessions, $avgpageloadtime, $goals));
  
    $body = new Google_Service_AnalyticsReporting_GetReportsRequest();
    $body-&gt;setReportRequests( array( $request) );
    return $analytics-&gt;reports-&gt;batchGet( $body );
  }
  
  
  function printResults(&amp;$reports) {
    for ( $reportIndex = 0; $reportIndex &lt; count( $reports ); $reportIndex++ ) {
      $report = $reports[ $reportIndex ];
      $header = $report-&gt;getColumnHeader();
      $dimensionHeaders = $header-&gt;getDimensions();
      $metricHeaders = $header-&gt;getMetricHeader()-&gt;getMetricHeaderEntries();
      
      $rows = $report-&gt;getData()-&gt;getRows();
  
      for ( $rowIndex = 0; $rowIndex &lt; count($rows); $rowIndex++) {
        $row = $rows[ $rowIndex ];
        $dimensions = $row-&gt;getDimensions();
        $metrics = $row-&gt;getMetrics();
        for ($i = 0; $i &lt; count($dimensionHeaders) &amp;&amp; $i &lt; count($dimensions); $i++) {
          print($dimensionHeaders[$i] . ": " . $dimensions[$i] . "\n");
  
        }
  
        echo "&lt;br&gt;";
  
        for ($j = 0; $j &lt; count( $metricHeaders ) &amp;&amp; $j &lt; count( $metrics ); $j++) {
          $entry = $metricHeaders[$j];
  
          $values = $metrics[$j];
          //print("Tipo de metrica: " . $entry-&gt;getType() . "\n" );
          for ( $valueIndex = 0; $valueIndex &lt; count( $values-&gt;getValues() ); $valueIndex++ ) {
            $value = $values-&gt;getValues()[ $valueIndex ];
            //echo $values-&gt;getValues()[$valueIndex]."&lt;br&gt;";
            //print($entry-&gt;getName() . ": " . $value . "&lt;br&gt;");
          }
        }
      }
    }
  }
  
  ?&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Thanks in advance.</p>