私はGoogle アナリティクス APIを使っていくつかの実験を行っていますが、順調に進んでいます (今のところ、Hello Analytics のチュートリアルに従っているだけです)。コードは、古いダミー ドメインで実行する時点までは問題なく実行されますが、現在開発中のサイト (joomla を使用) からコードを実行しようとすると、http-requests で問題が発生します。 .
Googleアカウントを選択してGAなどへのアクセスを許可できるGoogleへのリンクをユーザーに提供し、サイトにリダイレクトしても何も得られません。しばらくロードすると、サイトの 404 ページに移動します。
私のコードは次のようになります (コンポーネントのビューで default.php の中にあります。テスト目的で defined(j_exec) または die() を取り除きました):
<?php
require_once 'libraries/google-api-php-client/src/Google_Client.php';
require_once 'libraries/google-api-php-client/src/contrib/Google_AnalyticsService.php';
require_once 'libraries/google-api-php-client/src/contrib/Google_PlusService.php';
$session = JFactory::getSession();
$client = new Google_Client();
//$client->setAccessType('online');
$client->setApplicationName('sdffdgdfg');
$client->setClientId('my id ;)');
$client->setClientSecret('dsfdsf');
$client->setRedirectUri('asdsdf');
$client->setDeveloperKey('fdfg');
$client->setScopes('https://www.googleapis.com/auth/analytics.readonly');
// Set the client libraries to convert all the API responses from associative arrays into objects.
$client->setUseObjects(true);
//$plus = new Google_PlusService($client);
if( isset( $_GET['code'] ) ){
$client->authenticate($_GET['code'] );
$session->set('token', $client->getAccessToken());
//i took away the redirect here cuz i wanted to see that the code actually came :)
}
$token = $session->get('token');
if( isset( $token ) ){
$client->setAccessToken($session->get('token'));
}
if( !$client->getAccessToken() ){
$authUrl = $client->createAuthUrl();
print "<a class ='login' href='$authUrl'>Connect me!</a>";
}else{
echo "WE'RE IN!!";
//$analytics = new apiAnalyticsService($client);
//runMainDemo($analytics);
}
?>
$client->authenticate($_GET['code'] ); という行にコメントを付けると、問題は解決します。だから私はその道をたどり、最終的に言う行に来ました
$request = Google_Client::$io->makeRequest(new Google_HttpRequest(self::OAUTH2_TOKEN_URI, 'POST', array(), array(
'code' => $code,
'grant_type' => 'authorization_code',
'redirect_uri' => $this->redirectUri,
'client_id' => $this->clientId,
'client_secret' => $this->clientSecret
)));
この行は Google_OAuth2.php の 96 行目にあります。そのため、リクエストで何か問題が発生し、タイムアウトになります。私はそれについて何ができますか?これは私自身の問題解決の限界に近いので、本当に助けが必要です! joomlaと何か関係があるのでしょうか?または私のサーバー構成?(私のダミードメインとは異なります..)
よろしくお願いします!