繁体   English   中英

无法从joomla网站发出Google http请求

[英]Can't make google http request from joomla site

我正在尝试使用Google Analytics(分析)API,并且进展顺利(目前仅遵循其Hello Analytics(分析)方法)。 该代码可以很好地运行到我在旧的虚拟域上运行它时所处的位置,但是当我尝试从我当前正在开发的站点(使用joomla)中进行操作时,我遇到了HTTP请求问题。

我为用户提供了指向google的链接,我可以在其中选择google帐户并授予对GA等的访问权限,当它重定向到我的网站时,我什么也没有。 它加载了一段时间,然后将我发送到我的网站404页面。

我的代码如下所示(在组件视图中,它位于default.php内。出于测试目的,我删除了define(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有关吗? 还是我的服务器配置? (与我的虚拟域不同。)

在此先多谢!!

我忘了说这已经解决了。 我发邮件给我的服务器提供商之前,在这里发帖,他们告诉我他们与此无关。 然后,我再次通过电子邮件发送给他们(例如在此处发布2周后),他们说我的防火墙已关闭。 当他们打开它时,我进来了:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM