"구글 API 튜토리얼"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-<source +<syntaxhighlight , -</source> +</syntaxhighlight>))
 
(다른 사용자 한 명의 중간 판 5개는 보이지 않습니다)
13번째 줄: 13번째 줄:
{{참고|PHP 모듈 설치 확인}}
{{참고|PHP 모듈 설치 확인}}
*PHP 버전 5.2.1 이상, JSON 확장기능<ref>https://github.com/google/google-api-php-client</ref>
*PHP 버전 5.2.1 이상, JSON 확장기능<ref>https://github.com/google/google-api-php-client</ref>
<source lang='console'>
<syntaxhighlight lang='console'>
root@zetawiki:~# php -v
root@zetawiki:~# php -v
PHP 5.5.9-1ubuntu4.16 (cli) (built: Apr 20 2016 14:31:27)  
PHP 5.5.9-1ubuntu4.16 (cli) (built: Apr 20 2016 14:31:27)  
19번째 줄: 19번째 줄:
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
     with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies
     with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies
</source>
</syntaxhighlight>
<source lang='console'>
<syntaxhighlight lang='console'>
root@zetawiki:~# php -m | grep json
root@zetawiki:~# php -m | grep json
json
json
</source>
</syntaxhighlight>


==composer 설치==
==composer 설치==
30번째 줄: 30번째 줄:
==composer로 설치==
==composer로 설치==
* [[/usr/share/php/]]로 이동하여 composer로 구글 API 클라이언트 설치
* [[/usr/share/php/]]로 이동하여 composer로 구글 API 클라이언트 설치
<source lang='console'>
<syntaxhighlight lang='console'>
root@zetawiki:~# cd /usr/share/php/
root@zetawiki:~# cd /usr/share/php/
root@zetawiki:/usr/share/php# rm -f composer.*
root@zetawiki:/usr/share/php# rm -f composer.*
43번째 줄: 43번째 줄:
Writing lock file
Writing lock file
Generating autoload files
Generating autoload files
</source>
</syntaxhighlight>
* 폴더 이동
* 폴더 이동
<source lang='console'>
<syntaxhighlight lang='console'>
root@zetawiki:/usr/share/php# mv vendor/ google-api-php-client
root@zetawiki:/usr/share/php# mv vendor/ google-api
root@zetawiki:/usr/share/php#  
root@zetawiki:/usr/share/php#  
</source>
</syntaxhighlight>


==인클루드 테스트==
==인클루드 테스트==
* 홈폴더로 이동하여 테스트 파일 작성
* 홈폴더로 이동하여 테스트 파일 작성
<source lang='console'>
<syntaxhighlight lang='console'>
root@zetawiki:/usr/share/php# cd
root@zetawiki:/usr/share/php# cd
root@zetawiki:~# vi google-api-php-client_test.php
root@zetawiki:~# vi google-api_test.php
</source>
</syntaxhighlight>
<source lang='php'>
<syntaxhighlight lang='php'>
<?php
<?php
include 'google-api-php-client/autoload.php';
include 'google-api/autoload.php';
$client = new Google_Client();
$client = new Google_Client();
var_dump( $client );
var_dump( $client );
</source>
</syntaxhighlight>
<source lang='console'>
<syntaxhighlight lang='console'>
root@zetawiki:~# php google-api-php-client_test.php | head -5
root@zetawiki:~# php google-api_test.php | head  
object(Google_Client)#2 (9) {
Google_Client Object
  ["auth":"Google_Client":private]=>
(
  NULL
    [auth:Google_Client:private] =>  
  ["io":"Google_Client":private]=>
    [io:Google_Client:private] =>
  NULL
    [cache:Google_Client:private] =>
</source>
    [config:Google_Client:private] => Google_Config Object
        (
            [configuration:protected] => Array
                (
                    [application_name] =>
</syntaxhighlight>
:→ 이상없음
:→ 이상없음


75번째 줄: 80번째 줄:
* 예제 batch.php를 홈폴더로 복제·수정하여 테스트
* 예제 batch.php를 홈폴더로 복제·수정하여 테스트
* batch.php를 편집하여 라이브러리 위치를 맞춰주고, apiKey 입력
* batch.php를 편집하여 라이브러리 위치를 맞춰주고, apiKey 입력
<source lang='console'>
<syntaxhighlight lang='console'>
root@zetawiki:~# cp /usr/share/php/google-api-php-client/google/apiclient/examples/batch.php .
root@zetawiki:~# cp /usr/share/php/google-api/google/apiclient/examples/batch.php .
root@zetawiki:~# vi batch.php
root@zetawiki:~# vi batch.php
</source>
</syntaxhighlight>
<source lang='php' highlight='2,3,11,12,22,23'>
<syntaxhighlight lang='php' highlight='2,3,11,12,22,23'>
... (생략)
... (생략)
#### include_once "templates/base.php";
#### include_once "templates/base.php";
include_once "google-api-php-client/google/apiclient/examples/templates/base.php";
include_once "google-api/google/apiclient/examples/templates/base.php";
echo pageHeader("Batching Queries");
echo pageHeader("Batching Queries");


91번째 줄: 96번째 줄:
  ************************************************/
  ************************************************/
#### require_once realpath(dirname(__FILE__) . '/../src/Google/autoload.php');
#### require_once realpath(dirname(__FILE__) . '/../src/Google/autoload.php');
require_once "google-api-php-client/autoload.php";
require_once "google-api/autoload.php";


/************************************************
/************************************************
104번째 줄: 109번째 줄:
$apiKey = "AIzaSyBDEuxz8GIb0K2df4_hjlMOQSU68npWYrA";
$apiKey = "AIzaSyBDEuxz8GIb0K2df4_hjlMOQSU68npWYrA";
... (생략)
... (생략)
</source>
</syntaxhighlight>


==테스트==
==테스트==
<source lang='console'>
<syntaxhighlight lang='console'>
[root@zetawiki ~]# php batch.php  
root@zetawiki:~# php batch.php  
<h3>Results Of Call 1:</h3>The Writings of Henry David Thoreau<br />  
<h3>Results Of Call 1:</h3>Walden<br />
Walden<br />  
The Writings of Henry David Thoreau<br />  
The Maine Woods<br />  
A Week on the Concord and Merrimack Rivers<br />  
A Week on the Concord and Merrimack Rivers<br />  
... (생략)
Excursions<br />
Letters to Various Persons<br />
A Yankee in Canada<br />
A Hand-book of English Literature<br />
Neota Wilderness<br />
First Editions of American Authors<br />
<h3>Results Of Call 2:</h3>Catalog of Copyright Entries. Third Series<br />
English Literature of the 19th & 20th Centuries...<br />
Catalog of Copyright Entries. Part 1. [C] Group 3. Dramatic Composition and Motion Pictures. New Series<br />
Catalog of Copyright Entries. Part 1. [A] Group 1. Books. New Series<br />
Catalog of Copyright Entries. New Series<br />
Catalog of copyright entries<br />
Catalogue of English literature, comprising early plays, balads, poetry from Chaucer to Swinburne, books with colored plates, first editions, association books, authors' manuscripts, autograph letters...<br />
Catalog of Copyright Entries. Third Series<br />
Catalog of Copyright Entries<br />  
Catalog of Copyright Entries<br />  
Catalog of Copyright Entries. Part 1. [A] Group 1. Books. New Series<br />
Catalogue of Copyright Entries<br />
小泉信三文庫目録<br />  
小泉信三文庫目録<br />  
</source>
</syntaxhighlight>
:→ Book API가 잘 수행되었다. 다른 API도 사용해보자.<ref>단, API 종류에 따라 사용전 Enable 절차가 필요할 수 있다.</ref>
:→ Book API가 잘 수행되었다. 다른 API도 사용해보자.<ref>단, API 종류에 따라 사용전 Enable 절차가 필요할 수 있다.</ref>


123번째 줄: 140번째 줄:
*[[구글 API 튜토리얼 2 - ISBN으로 책정보 조회]]
*[[구글 API 튜토리얼 2 - ISBN으로 책정보 조회]]
*[[구글 애널리틱스 API 시작하기]]
*[[구글 애널리틱스 API 시작하기]]
*[[The calling IP address 135.79.246.80 does not match the IP restrictions configured on the API key. Please use the API Console to update your key restrictions.]]


==주석==
==주석==

2021년 9월 24일 (금) 23:27 기준 최신판

1 개요[ | ]

Google API tutorial
구글 API 시작하기, 구글 API 튜토리얼
구글API PHP 클라이언트 시작하기
google-api-php-client 사용해보기
  • google-api-php-client를 설치하고, 포함된 예제를 하나 실행해보자.

2 사전작업[ | ]

3 설치요건 확인[ | ]

  • PHP 버전 5.2.1 이상, JSON 확장기능[1]
root@zetawiki:~# php -v
PHP 5.5.9-1ubuntu4.16 (cli) (built: Apr 20 2016 14:31:27) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
    with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies
root@zetawiki:~# php -m | grep json
json

4 composer 설치[ | ]

5 composer로 설치[ | ]

  • /usr/share/php/로 이동하여 composer로 구글 API 클라이언트 설치
root@zetawiki:~# cd /usr/share/php/
root@zetawiki:/usr/share/php# rm -f composer.*
root@zetawiki:/usr/share/php# composer require 'google/apiclient'
Using version ^1.1 for google/apiclient
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing google/apiclient (1.1.7)
    Downloading: 100%         

Writing lock file
Generating autoload files
  • 폴더 이동
root@zetawiki:/usr/share/php# mv vendor/ google-api
root@zetawiki:/usr/share/php#

6 인클루드 테스트[ | ]

  • 홈폴더로 이동하여 테스트 파일 작성
root@zetawiki:/usr/share/php# cd
root@zetawiki:~# vi google-api_test.php
<?php
include 'google-api/autoload.php';
$client = new Google_Client();
var_dump( $client );
root@zetawiki:~# php google-api_test.php | head 
Google_Client Object
(
    [auth:Google_Client:private] => 
    [io:Google_Client:private] => 
    [cache:Google_Client:private] => 
    [config:Google_Client:private] => Google_Config Object
        (
            [configuration:protected] => Array
                (
                    [application_name] =>
→ 이상없음

7 batch.php 테스트[ | ]

  • 예제 batch.php를 홈폴더로 복제·수정하여 테스트
  • batch.php를 편집하여 라이브러리 위치를 맞춰주고, apiKey 입력
root@zetawiki:~# cp /usr/share/php/google-api/google/apiclient/examples/batch.php .
root@zetawiki:~# vi batch.php
... (생략)
#### include_once "templates/base.php";
include_once "google-api/google/apiclient/examples/templates/base.php";
echo pageHeader("Batching Queries");

/************************************************
  We're going to use the simple access to the
  books API again as an example, but this time we
  will batch up two queries into a single call.
 ************************************************/
#### require_once realpath(dirname(__FILE__) . '/../src/Google/autoload.php');
require_once "google-api/autoload.php";

/************************************************
  We create the client and set the simple API
  access key. If you comment out the call to
  setDeveloperKey, the request may still succeed
  using the anonymous quota.
 ************************************************/
$client = new Google_Client();
$client->setApplicationName("Client_Library_Examples");
#### $apiKey = "<YOUR_API_KEY>"; // Change to your API key.
$apiKey = "AIzaSyBDEuxz8GIb0K2df4_hjlMOQSU68npWYrA";
... (생략)

8 테스트[ | ]

root@zetawiki:~# php batch.php 
<h3>Results Of Call 1:</h3>Walden<br /> 
The Writings of Henry David Thoreau<br /> 
The Maine Woods<br /> 
A Week on the Concord and Merrimack Rivers<br /> 
Excursions<br /> 
Letters to Various Persons<br /> 
A Yankee in Canada<br /> 
A Hand-book of English Literature<br /> 
Neota Wilderness<br /> 
First Editions of American Authors<br /> 
<h3>Results Of Call 2:</h3>Catalog of Copyright Entries. Third Series<br /> 
English Literature of the 19th & 20th Centuries...<br /> 
Catalog of Copyright Entries. Part 1. [C] Group 3. Dramatic Composition and Motion Pictures. New Series<br /> 
Catalog of Copyright Entries. Part 1. [A] Group 1. Books. New Series<br /> 
Catalog of Copyright Entries. New Series<br /> 
Catalog of copyright entries<br /> 
Catalogue of English literature, comprising early plays, balads, poetry from Chaucer to Swinburne, books with colored plates, first editions, association books, authors' manuscripts, autograph letters...<br /> 
Catalog of Copyright Entries. Third Series<br /> 
Catalog of Copyright Entries<br /> 
小泉信三文庫目録<br />
→ Book API가 잘 수행되었다. 다른 API도 사용해보자.[2]

9 같이 보기[ | ]

10 주석[ | ]

  1. https://github.com/google/google-api-php-client
  2. 단, API 종류에 따라 사용전 Enable 절차가 필요할 수 있다.
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}