약 일주일 후 - 그리고 물론 같은 날에이 질문을 게시합니다. 마침내이 문제를 해결할 수있었습니다.
내가 their github에서 (PHP 용) 최신 Google 클라이언트 API를 다운로드 : 내가 가야하는 방법
이입니다.
내 application/third_party 폴더에 Google 폴더 (src)를 추가했습니다.
require_once(BASEPATH . '../application/third_party/Google/Client.php');
require_once(BASEPATH . '../application/third_party/Google/Service/Analytics.php');
그럼 난 당신이
Google Console에서 얻을 프로젝트> API를 & 인증을 선택하는 서비스 계정 (과 권한 부여를 위해 그 아래에 다음 코드를 추가 : 내 컨트롤러 내부
나는 수행하여 필요한 파일을 포함 > 자격 증명> 그런 다음, 완료되면 눌러 "새 P12 키 생성"서비스 계정을 선택, 새로운 클라이언트 ID를 생성하고 THIRD_PARTY에 해당 키를 추가/구글 폴더 :
이
session_start();
$client_id = '<YOUR_CLIENT_ID>'; //Client ID
$service_account_name = '<YOUR_CLIENT_EMAIL>'; //Email Address
$key_file_location = BASEPATH . '../application/third_party/Google/<YOUR KEY.p12>'; //key.p12
$client = new Google_Client();
$client->setApplicationName("ApplicationName");
$service = new Google_Service_Analytics($client);
if (isset($_SESSION['service_token'])) {
$client->setAccessToken($_SESSION['service_token']);
}
$key = file_get_contents($key_file_location);
$cred = new Google_Auth_AssertionCredentials(
$service_account_name,
array(
'https://www.googleapis.com/auth/analytics',
),
$key,
'notasecret'
);
$client->setAssertionCredentials($cred);
if($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion($cred);
}
$_SESSION['service_token'] = $client->getAccessToken();
아래 코드는 구경에게 있습니다 지난 삼십일일
$analytics = new Google_Service_Analytics($client);
$profileId = "ga:<YOUR_PROFILE_ID>";
$startDate = date('Y-m-d', strtotime('-31 days')); // 31 days from now
$endDate = date('Y-m-d'); // todays date
$metrics = "ga:sessions";
$optParams = array("dimensions" => "ga:date");
$results = $analytics->data_ga->get($profileId, $startDate, $endDate, $metrics, $optParams);
$data['report'] = $results->rows; //To send it to the view later
에서 R 점점 세션 (페이지 방문) use this link, 당신이 사용할 수있는 모든 측정 기준과 측정 항목을 얻으려면. 보기로 전송하는 방법에 대한 예 :
$this->view->load('your_view', $data);
이 (뷰)를 JS에서 난 그냥 Google charts를 사용하는 차트로 써내, 난 그냥 $에서 데이터를 루프 데이터 [ '보고서' ] 차트를 그립니다.
희망은 앞으로이 문제가있는 사람들에게 도움이 될 것입니다.
사람들이 왜 이런 문제를 겪고있는 지 이해할 수없는 이유가 있습니다. 나는 Codeigniter의 Sparks 용 플러그인을 사용해 보았습니다.하지만 그 플러그인은 2 살입니다. API가 오래된 것입니다. 그리고 googles 웹 사이트의 예제에서 명명 규칙이 잘못되었습니다 ... – Michael