我正在尝试使用 Google Analytics(分析)API 进行一些实验,并且它正在顺利进行(现在只关注他们的Hello Analytics论坛)。代码运行得很好,直到我在我的旧虚拟域上运行它,但当我尝试从我正在开发的网站(使用joomla)时,我遇到了http请求的问题
我向用户提供了一个谷歌链接,我可以选择谷歌帐户并授予对GA等的访问权限,当它重定向到我的网站时,我什么也得不到。它会加载一段时间,然后将我发送到我的网站404页面。
我的代码看起来像这样(它在组件视图中的default.php中。我带走了定义的(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-&gt; 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有关吗?还是我的服务器配置? (与我的虚拟域名不同。)
提前多多感谢!!
答案 0 :(得分:0)
我忘了说这已经解决了。我在发布这里之前通过电子邮件发送了我的服务器提供商,他们告诉我他们与此无关。然后我再次通过电子邮件发送给他们(就像发布后两周一样),他们说我的防火墙已关闭。当他们打开它时,我进入了:)