편집을 취소할 수 있습니다. 이 편집을 되돌리려면 아래의 바뀐 내용을 확인한 후 게시해주세요.
최신판 | 당신의 편집 | ||
2번째 줄: | 2번째 줄: | ||
;구글 Analytics API 시작하기 | ;구글 Analytics API 시작하기 | ||
;구글 애널리틱스 API 튜토리얼 | ;구글 애널리틱스 API 튜토리얼 | ||
==목적 / 목표== | ==목적 / 목표== | ||
27번째 줄: | 26번째 줄: | ||
*파일명을 client_secrets.p12으로 변경 | *파일명을 client_secrets.p12으로 변경 | ||
*서버에 업로드 | *서버에 업로드 | ||
<source lang=' | <source lang='cli'> | ||
[root@zetawiki ~]# ll *.p12 | [root@zetawiki ~]# ll *.p12 | ||
-rw-r--r-- 1 root root 1732 Jun 22 22:29 client_secrets.p12 | -rw-r--r-- 1 root root 1732 Jun 22 22:29 client_secrets.p12 | ||
</source> | </source> | ||
==예제 | ==예제 다운로드·수정== | ||
<source lang=' | <source lang='cli'> | ||
[root@zetawiki ~]# wget https://developers.google.com/analytics/resources/samples/service-php.txt | [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 | --2015-06-22 23:07:25-- https://developers.google.com/analytics/resources/samples/service-php.txt | ||
46번째 줄: | 45번째 줄: | ||
2015-06-22 23:07:26 (12.4 MB/s) - “service-php.txt” saved [3353/3353] | 2015-06-22 23:07:26 (12.4 MB/s) - “service-php.txt” saved [3353/3353] | ||
</source> | </source> | ||
<source lang=' | <source lang='cli'> | ||
[root@zetawiki ~]# head service-php.txt | [root@zetawiki ~]# head service-php.txt | ||
<?php | <?php | ||
59번째 줄: | 58번째 줄: | ||
// 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로 복사 | * service-php.txt를 HelloAnalytics.php로 복사 | ||
* 라이브러리 위치 수정 | * 라이브러리 위치 수정 | ||
* API용 구글 이메일, p12 파일명 입력 | * API용 구글 이메일, p12 파일명 입력 | ||
<source lang=' | <source lang='cli'> | ||
[root@zetawiki ~]# cp service-php.txt HelloAnalytics.php | [root@zetawiki ~]# cp service-php.txt HelloAnalytics.php | ||
[root@zetawiki ~]# vi HelloAnalytics.php | [root@zetawiki ~]# vi HelloAnalytics.php | ||
</source> | </source> | ||
<source lang=' | <source lang='diff'> | ||
< | 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>'; | |||
--- | |||
require_once 'Google/autoload.php'; | > $service_account_email = '871045965516-m6pxhmgmk0f6l6cdeq5alsbwh9own7ma.apps.googleusercontent.com'; | ||
> $key_file_location = 'client_secrets.p12'; | |||
$service_account_email = '871045965516-m6pxhmgmk0f6l6cdeq5alsbwh9own7ma.apps.googleusercontent.com'; | |||
$key_file_location = 'client_secrets.p12'; | |||
</source> | </source> | ||
==테스트 (실패)== | ==테스트 (실패)== | ||
<source lang=' | <source lang='cli'> | ||
[root@zetawiki ~]# php HelloAnalytics.php | [root@zetawiki ~]# php HelloAnalytics.php | ||
PHP Fatal error: Uncaught exception 'Google_Service_Exception' with message 'Error calling GET https://www.googleapis.com/analytics/v3/management/accounts: (403) User does not have any Google Analytics account.' in /usr/share/php/vendor/Google/Http/REST.php:110 | PHP Fatal error: Uncaught exception 'Google_Service_Exception' with message 'Error calling GET https://www.googleapis.com/analytics/v3/management/accounts: (403) User does not have any Google Analytics account.' in /usr/share/php/vendor/Google/Http/REST.php:110 | ||
Stack trace: | Stack trace: | ||
#0 /usr/share/php/vendor/Google/Http/REST.php(62): Google_Http_REST::decodeHttpResponse(Object(Google_Http_Request), Object(Google_Client)) | #0 /usr/share/php/vendor/Google/Http/REST.php(62): Google_Http_REST::decodeHttpResponse(Object(Google_Http_Request), Object(Google_Client)) | ||
... ( | #1 [internal function]: Google_Http_REST::doExecute(Object(Google_Client), Object(Google_Http_Request)) | ||
#2 /usr/share/php/vendor/Google/Task/Runner.php(174): call_user_func_array(Array, Array) | |||
#3 /usr/share/php/vendor/Google/Http/REST.php(46): Google_Task_Runner->run() | |||
#4 /usr/share/php/vendor/Google/Client.php(593): Google_Http_REST::execute(Object(Google_Client), Object(Google_Http_Request)) | |||
#5 /usr/share/php/vendor/Google/Service/Resource.php(237): Google_Client->execute(Object(Google_Http_Request)) | |||
#6 /usr/share/php/vendor/Google/Service/Analytics.php(2259): Google_Service_Resource->call('list', Array, 'Google_Serv in /usr/share/php/vendor/Google/Http/REST.php on line 110 | |||
</source> | </source> | ||
102번째 줄: | 97번째 줄: | ||
*[관리] 탭 선택 | *[관리] 탭 선택 | ||
*[사용자 관리] 메뉴 클릭 | *[사용자 관리] 메뉴 클릭 | ||
*다음 사용자에게 권한 추가: | *다음 사용자에게 권한 추가: 404883990642-aoauutb4ktnc3s5vl57eg1uaeu94toh8@developer.gserviceaccount.com<ref>계정 권한: 읽고 분석하기</ref> | ||
*[추가] 버튼 클릭 | *[추가] 버튼 클릭 | ||
==테스트 2 (성공)== | ==테스트 2 (성공)== | ||
<source lang=' | <source lang='cli'> | ||
[root@zetawiki ~]# php HelloAnalytics.php | [root@zetawiki ~]# php HelloAnalytics.php | ||
First view (profile) found: zetawiki.com | First view (profile) found: zetawiki.com | ||
116번째 줄: | 111번째 줄: | ||
*[[구글 API 시작하기]] | *[[구글 API 시작하기]] | ||
==참고 자료== | |||
==참고== | |||
*https://developers.google.com/analytics/devguides/reporting/core/v3/quickstart/service-php | *https://developers.google.com/analytics/devguides/reporting/core/v3/quickstart/service-php | ||
*http://stackoverflow.com/questions/12837748/analytics-google-api-error-403-user-does-not-have-any-google-analytics-account | *http://stackoverflow.com/questions/12837748/analytics-google-api-error-403-user-does-not-have-any-google-analytics-account | ||
[[분류: 구글 API]] | [[분류: 구글 API]] | ||