"구글 Analytics API 시작하기"의 두 판 사이의 차이

57번째 줄: 57번째 줄:
   // Use the developers console and replace the values with your
   // Use the developers console and replace the values with your
</source>
</source>
* service-php.txt를 HelloAnalytics.php로 복사
* 라이브러리 위치 수정
* API용 구글 이메일, p12 파일명 입력
<source lang='cli'>
<source lang='cli'>
[root@zetawiki ~]# cp service-php.txt HelloAnalytics.php
[root@zetawiki ~]# cp service-php.txt HelloAnalytics.php
[root@zetawiki ~]# sed -i "s/require_once 'google-api-php-client\/src\/Google\/autoload.php';/include '\/usr\/share\/php\/vendor\/Google\/autoload.php';/g" HelloAnalytics.php
[root@zetawiki ~]# vi HelloAnalytics.php
[root@zetawiki ~]# diff service-php.txt HelloAnalytics.php
</source>
<source lang='diff'>
8c8
8c8
<  require_once 'google-api-php-client/src/Google/autoload.php';
<  require_once 'google-api-php-client/src/Google/autoload.php';
---
---
include '/usr/share/php/vendor/Google/autoload.php';
require_once '/usr/share/php/vendor/Google/autoload.php';
12,13c12,13
<  $service_account_email = '<Replace with your service account email address.>';
<  $key_file_location = '<Replace with /path/to/generated/client_secrets.p12>';
---
>  $service_account_email = '871045965516-m6pxhmgmk0f6l6cdeq5alsbwh9own7ma.apps.googleusercontent.com';
>  $key_file_location = 'API_Project-7bq7391w37g9.p12';
</source>
</source>



2015년 6월 22일 (월) 23:16 판

Google Analytics API tutorial
구글 Analytics API 시작하기
구글 애널리틱스 API 튜토리얼

1 목적 / 목표

  • 정기예약작업(crontab)으로 Analytics 데이터를 수집하여 MySQL에 보관
  • PHP 라이브러리를 이용하여 기본 프로그램 작성
자바, 파이썬, PHP, 자바스크립트 라이브러리가 제공되는데 여기서는 PHP로 한다.

2 사전 작업

3 API 활성화

"Enabled Analytics API"

4 P12 키 생성·업로드

  • 왼쪽 메뉴(Sidebar)에서 Credentials 클릭
  • [Generate new P12 key] 버튼 클릭
API Project-7bq7391w37g9.p12 파일 다운로드됨
  • 서버에 업로드
[root@zetawiki ~]# ll *.p12
-rw-r--r-- 1 root root 1732 Jun 22 22:29 API_Project-7bq7391w37g9.p12

5 예제 다운로드·실행

[root@zetawiki ~]# wget https://developers.google.com/analytics/resources/samples/service-php.txt
--2015-06-22 23:07:25--  https://developers.google.com/analytics/resources/samples/service-php.txt
Resolving developers.google.com... 58.123.102.118, 58.123.102.98, 58.123.102.119, ...
Connecting to developers.google.com|58.123.102.118|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3353 (3.3K) [text/plain]
Saving to: “service-php.txt”

100%[================================================>] 3,353       --.-K/s   in 0s      

2015-06-22 23:07:26 (12.4 MB/s) - “service-php.txt” saved [3353/3353]
[root@zetawiki ~]# head service-php.txt
<?php

function getService()
{
  // Creates and returns the Analytics service object.

  // Load the Google API PHP Client Library.
  require_once 'google-api-php-client/src/Google/autoload.php';

  // Use the developers console and replace the values with your
  • service-php.txt를 HelloAnalytics.php로 복사
  • 라이브러리 위치 수정
  • API용 구글 이메일, p12 파일명 입력
[root@zetawiki ~]# cp service-php.txt HelloAnalytics.php
[root@zetawiki ~]# vi HelloAnalytics.php
8c8
<   require_once 'google-api-php-client/src/Google/autoload.php';
---
>   require_once '/usr/share/php/vendor/Google/autoload.php';
12,13c12,13
<   $service_account_email = '<Replace with your service account email address.>';
<   $key_file_location = '<Replace with /path/to/generated/client_secrets.p12>';
---
>   $service_account_email = '871045965516-m6pxhmgmk0f6l6cdeq5alsbwh9own7ma.apps.googleusercontent.com';
>   $key_file_location = 'API_Project-7bq7391w37g9.p12';

6 같이 보기

7 참고 자료

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}