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 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)