0

我对 codenvy 和 php 相当陌生,但我已经仔细检查了以下内容,但是当我使用以下代码启动它时,我仍然没有被要求 oauth 进入谷歌。我按照这里的说明进行操作。下面有什么明显的错误吗?

https://developers.google.com/analytics/solutions/articles/hello-analytics-api

 <?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';
   ?>
4

1 回答 1

0

如果您的项目是公开的,请与 Codenvy 的工厂功能分享。因此,每个人都可以查看 OAuth 集成有什么问题。(您可以在 IDE 的左侧面板上访问工厂)

于 2014-11-15T21:15:53.197 回答