0
我對codenvy和PHP是相當新的,但我已經doublechecked以下,但我仍然沒有要求oauth進入谷歌,當我用下面的代碼啓動此。我遵循這裏的指示。下面的任何明顯的錯誤?使用Codenvy OAuth谷歌與PHP
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';
?>