Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Codenvy与php一起使用OAuth-Google_Php_Oauth_Google Analytics_Codenvy - Fatal编程技术网

使用Codenvy与php一起使用OAuth-Google

使用Codenvy与php一起使用OAuth-Google,php,oauth,google-analytics,codenvy,Php,Oauth,Google Analytics,Codenvy,我对codenvy和php相当陌生,但我已经仔细检查了以下内容,但当我用下面的代码启动它时,我仍然没有被要求进入谷歌。我听从这里的指示。下面有什么明显的错误吗 如果您的项目是公开的,请与Codenvy的factory功能共享。因此,每个人都可以看到OAuth集成的问题所在。 您可以访问IDE左面板上的factory <?php require_once 'src/Google/Client.php'; require_once 'src/Google/Service/Analyt

我对codenvy和php相当陌生,但我已经仔细检查了以下内容,但当我用下面的代码启动它时,我仍然没有被要求进入谷歌。我听从这里的指示。下面有什么明显的错误吗


如果您的项目是公开的,请与Codenvy的factory功能共享。因此,每个人都可以看到OAuth集成的问题所在。 您可以访问IDE左面板上的factory

 <?php
  require_once 'src/Google/Client.php';
  require_once 'src/Google/Service/Analytics.php';
   session_start();

   $client = new Google_Client();
   $client->setApplicationName('Hello Analytics API Sample');

    // Visit https://console.developers.google.com/ to generate your
    // client id, client secret, and to register your redirect uri.
    $client->setClientId('CONFIRMED THIS IS CORRECT');
    $client->setClientSecret('CONFIRMED THIS IS CORRECT');
    $client->setRedirectUri('https://codenvycorp.com/api/oauth/callback');
    $client->setDeveloperKey('CONFIRMED THIS IS CORRECT');
    $client->setScopes(array('https://www.googleapis.com/auth/analytics.readonly'));

    // Magic. Returns objects from the Analytics Service instead of associative arrays.
    $client->setUseObjects(true);

   if (isset($_GET['code'])) {
    $client->authenticate();
    $_SESSION['token'] = $client->getAccessToken();
    $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
    header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
   }

   if (isset($_SESSION['token'])) {
    $client->setAccessToken($_SESSION['token']);
   }

   if (!$client->getAccessToken()) {
      $authUrl = $client->createAuthUrl();
      print "<a class='login' href='$authUrl'>Connect Me!</a>";

    } else {
      $analytics = new apiAnalyticsService($client);
      runMainDemo($analytics);
    }  

   echo 'Hello World 321';
   ?>