2013-05-26 61 views
0

重要編輯:發現這個問題是由我的網絡服務器(我不知道如何解決這個問題) - 標籤改變。我使用最新的XAMPP。谷歌分析服務API(ERR_CONNECTION_RESET)

我試圖建立服務器與谷歌Analytics(分析)API使用OAuth本指南以下服務器連接: Service Applications and Google Analytics API V3: Server-to-server OAuth2 authentication?

我有以下代碼:

require_once 'google-api-php-client/src/Google_Client.php'; 
require_once 'google-api-php-client/src/contrib/Google_AnalyticsService.php'; 

// create client object and set app name 
$client = new Google_Client(); 
$client -> setApplicationName("------------"); // name of your app 

// set assertion credentials 
$client->setAssertionCredentials(
    new Google_AssertionCredentials(
    "[email protected]", // email you added to GA 
    array('https://www.googleapis.com/auth/analytics.readonly'), 
    file_get_contents("-:/-----------/-----/------/----/---------------------------------------------------.p12") // keyfile you downloaded 

)); 

// other settings 
$client->setClientId("------------.apps.googleusercontent.com");   // from API console 
$client->setAccessType('offline_access'); // this may be unnecessary? 

// create service and get data 
$service = new Google_AnalyticsService($client); 

$ids = "ga:--------"; 
$startDate = "2013-05-01"; 
$endDate = "2013-05-26"; 
$metrics = "ga:visitors"; 

var_dump($service->data_ga->get($ids, $startDate, $endDate, $metrics)); 

導致HTTP錯誤#101(ERR_CONNECTION_RESET )。我的問題類似於:Service Applications and Google Analytics API V3: Error 101 (net::ERR_CONNECTION_RESET)但我沒有其他電話Google_AnalyticsService()

我有PHP版本5.4.7(XAMPP版本)與啓用OpenSSL(通過在php.ini未啓用行啓用)。

非常感謝您提供任何答案。如何處理這樣的問題(產生一些HTTP錯誤並停止?是否有日誌產生任何有用的信息?)?

編輯:從帖子複製代碼:"Not sufficient permissions" google analytics API service account給我導致相同的錯誤(沒有其他消息打印)。

回答

1

我找到了解決這個問題的方法。這是由Apache和PHP共同造成的 - 它們使用不同版本的OpenSSL。

  • 第一個解決方法(如一個我把它寫05-28-3013不工作對我來說)的XAMPP 1.8.1(發佈日期2012年9月30日)與Apache /bin/文件夾中的替換文件ssleay32.dlllibeay32.dll這些來自php文件夾。它不適合我,因爲mod_ssl無法與PHP的DLL一起工作。
  • 第二個解決方法是安裝其他軟件包。就個人而言,我轉而使用了同步版本的OpenSSL和Apache的ZendServer。

當然,你總是可以建立自己的Apache和PHP,確保你有最新版本的OpenSSL和mod_ssl合作。

+0

Soltysik我有同樣的問題,我試着用XAMPP 1.7.7繞過#1,它工作。但是,請你讓我知道這個解決方案的更多背景,因爲我看到Apache DLL被更新,然後PHP DLL被更新。爲什麼更新後的DLL會出現此問題? – Arfeen

+1

@ Arfeen原因可能會有所不同; DLL文件包含已編譯的無頭代碼。一個DLL文件可能包含另一個不存在的代碼(例如,函數)。切換它們可能會導致正在使用它們的程序不穩定。 –