doujiabing1228 2013-05-07 09:10
浏览 47
已采纳

无法从joomla网站发出谷歌http请求

I'm doing some experimenting with the Google Analytics API and it's coming along nicely (just following their Hello Analytics turorial for now). The code runs fine up to the point where I'm at when i run it on my old dummy domain, but when I try to do it fromm a site I'm currently developing (with joomla) I get problems with the http-requests.

I give the user a link to google where I can choose google account and grant access to GA etc and when it redirects to my site I get nothing. It loads for a while then sends me to my sites 404 page.

My code looks like this (it's inside the default.php in a view of a component. I took away the defined(j_exec) or die() for testing purposes):

<?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);

}


?>

The problem stops if I comment the line $client->authenticate($_GET['code'] ); so I've followed that trail and finally come to a line saying

$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
      )));

This line resides in Google_OAuth2.php line 96. So something goes wrong with the request and it time out. What can I do about it? This is pretty much as far as my own problem solving takes me so I really need some help with this! Could it be something to do with joomla? Or my server configuration? (Not same as my dummy domain..)

Thanks a lot in advance!!

  • 写回答

1条回答 默认 最新

  • dongzhong1929 2013-09-06 06:44
    关注

    I forgot to say that this is solved. I emailed my server provider before posting here and they told me that they had nothing to do with this. I then emailed them again (like 2 weeks after posting here) and they said my firewall was closed. When they opened it I got in :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 写uniapp时遇到的问题
  • ¥15 matlab有限元法求解梁带有若干弹簧质量系统的固有频率
  • ¥15 找一个网络防御专家,外包的
  • ¥100 能不能让两张不同的图片md5值一样,(有尝)
  • ¥15 informer代码训练自己的数据集,改参数怎么改
  • ¥15 请看一下,学校实验要求,我需要具体代码
  • ¥50 pc微信3.6.0.18不能登陆 有偿解决问题
  • ¥20 MATLAB绘制两隐函数曲面的交线
  • ¥15 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流