2013-05-07 32 views
0

我正在做一些谷歌分析API的實驗,它很好地沿着它(現在只是遵循他們的Hello Analytics)。代碼運行良好,直到我在我的舊的虛擬域上運行時,但當我嘗試從我正在開發的一個站點(使用joomla)執行時,我遇到了http請求的問題。不能讓joomla網站的谷歌http請求

我給用戶一個鏈接到谷歌,我可以選擇谷歌帳戶和授予訪問GA等,當它重定向到我的網站,我什麼也得不到。它加載了一段時間,然後將我發送到我的網站404頁面。

我的代碼看起來是這樣的(這是在組件的景緻如default.php裏面我帶走了定義(j_exec)或死亡()用於測試目的。):

<?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有關嗎?或者我的服務器配置? (不同於我的虛擬域..)

非常感謝提前!

+0

它看起來像重定向url沒有找到你已經通過 – 2013-05-07 09:13:48

+0

是的,但事情是,如果我註釋掉$ client-> authenticate一切都很好,除非我無法驗證在那案例.. – user2354664 2013-05-07 09:43:34

+0

嘗試檢查!空($ _GET ['code']) – 2013-05-07 10:14:37

回答

0

我忘了說這個問題已經解決了。我在發佈之前發郵件給我的服務器提供商,他們告訴我他們與此無關。然後我再次通過電子郵件發送郵件(比如發佈後兩週),他們說我的防火牆已關閉。當他們打開它,我得到了:)