google-analytics-api
메타 데이터 API
수색…
통사론
- HTTP GET https://www.googleapis.com/analytics/v3/metadata/ {reportType} / columns? key = {APIKey}
- HTTP GET https://www.googleapis.com/analytics/v3/metadata/ {reportType} / columns? access_token = {Access_token}
매개 변수
매개 변수 이름 | 기술 |
---|---|
보고서 유형 | 보고서 유형. 허용되는 값 : ga . 여기서 GA 는 Core Reporting API에 해당합니다. |
비고
메타 데이터 API 는 Google 애널리틱스보고 API (v2, v3 및 v4)에 표시되는 열 (예 : 측정 기준 및 측정 항목)의 목록 및 속성을 반환합니다. 반환되는 속성에는 UI 이름, 설명, 세그먼트 지원 등이 포함됩니다.
Metadata API를 사용하여 다음을 수행 할 수 있습니다.
- 새 열 자동 찾기
- Google 애널리틱스보고 API의 모든 측정 기준 및 측정 항목 속성에 액세스
측정 기준 및 측정 항목 탐색기 와 동일한 목록입니다.
참고 : 실시간 및 다중 채널 유입 경로 측정 기준 및 측정 항목은 현재 사용할 수 없습니다.
나머지 예제
Metadata API 호출은 HTTP Get과 함께 수행됩니다.
공개 API 키 사용
GET https://www.googleapis.com/analytics/v3/metadata/ga/columns?key= {YOUR_API_KEY}
Oauth2 또는 서비스 계정 인증에서 액세스 토큰 사용
GET https://www.googleapis.com/analytics/v3/metadata/ga/columns?access_token= {Authentcated_Access_Token}
Java 예제
Java 클라이언트 라이브러리를 사용합니다.
/**
* 1. Execute a Metadata Request
* An application can request columns data by calling the list method on the Analytics service object.
* The method requires an reportType parameter that specifies the column data to retrieve.
* For example, the following code requests columns for the ga report type.
*/
try {
Columns results = getMetadata(analytics);
// Success
} catch (GoogleJsonResponseException e) {
// Catch API specific errors.
handleApiError(e);
} catch (IOException e) {
// Catch general parsing network errors.
e.printStackTrace();
}
/**
* 2. Print out the Columns data
* The components of the result can be printed out as follows:
*/
private static Columns getMetadata(Analytics analytics) throws IOException {
String reportType = "ga";
return analytics.metadata()
.columns()
.list(reportType)
.execute();
}
private static void printMetadataReport(Columns results) {
System.out.println("Metadata Response Report");
printReportInfo(results);
printAttributes(results.getAttributeNames());
printColumns(results.getItems());
}
private static void printReportInfo(Columns results) {
System.out.println("## Metadata Report Info ##");
System.out.println("Kind: " + results.getKind());
System.out.println("Etag: " + results.getEtag());
System.out.println("Total Results: " + results.getTotalResults());
System.out.println();
}
private static void printAttributes(List<String> attributeNames) {
System.out.println("## Attribute Names ##");
for (String attribute : attributeNames) {
System.out.println(attribute);
}
}
private static void printColumns(List<Column> columns) {
System.out.println("## Columns ##");
for (Column column : columns) {
System.out.println();
System.out.println("Column ID: " + column.getId());
System.out.println("Kind: " + column.getKind());
Map<String, String> columnAttributes = column.getAttributes();
for (Map.Entry<String, String> attribute: columnAttributes.entrySet()) {
System.out.println(attribute.getKey() + ": " + attribute.getValue());
}
}
}
참고 : Metadata.list 에서 복사 한 첫 번째 버전
PHP 예제
PHP 클라이언트 라이브러리를 사용합니다.
/**
* 1. Execute a Metadata Request
* An application can request columns data by calling the list method on the Analytics service object.
* The method requires an reportType parameter that specifies the column data to retrieve.
* For example, the following code requests columns for the ga report type.
*/
try {
$results = $analytics->metadata_columns->listMetadataColumns('ga');
// Success
} catch (apiServiceException $e) {
// Handle API service exceptions.
$error = $e->getMessage();
}
/**
* 2. Print out the Columns data
* The components of the result can be printed out as follows:
*/
function printMetadataReport($results) {
print '<h1>Metadata Report</h1>';
printReportInfo($results);
printAttributes($results);
printColumns($results);
}
function printReportInfo(&$results) {
$html = '<h2>Report Info</h2>';
$html .= <<<HTML
<pre>
Kind = {$results->getKind()}
Etag = {$results->getEtag()}
Total Results = {$results->getTotalResults()}
</pre>
HTML;
print $html;
}
function printAttributes(&$results) {
$html = '<h2>Attribute Names</h2><ul>';
$attributes = $results->getAttributeNames();
foreach ($attributes as $attribute) {
$html .= '<li>'. $attribute . '</li>';
}
$html .= '</ul>';
print $html;
}
function printColumns(&$results) {
$columns = $results->getItems();
if (count($columns) > 0) {
$html = '<h2>Columns</h2>';
foreach ($columns as $column) {
$html .= '<h3>' . $column->getId() . '</h3>';
$column_attributes = $column->getAttributes();
foreach ($column_attributes as $name=>$value) {
$html .= <<<HTML
<pre>
{$name}: {$value}
</pre>
HTML;
}
}
} else {
$html = '<p>No Results Found.</p>';
}
print $html;
}
참고 : metadata.list 에서 복사 한 원본 버전
파이썬 예제
파이썬 클라이언트 라이브러리를 사용합니다.
# 1. Execute a Metadata Request
# An application can request columns data by calling the list method on the Analytics service object.
# The method requires an reportType parameter that specifies the column data to retrieve.
# For example, the following code requests columns for the ga report type.
try:
results = service.metadata().columns().list(reportType='ga').execute()
except TypeError, error:
# Handle errors in constructing a query.
print ('There was an error in constructing your query : %s' % error)
except HttpError, error:
# Handle API errors.
print ('Arg, there was an API error : %s : %s' %
(error.resp.status, error._get_reason()))
# 2. Print out the Columns data
# The components of the result can be printed out as follows:
def print_metadata_report(results):
print 'Metadata Response Report'
print_report_info(results)
print_attributes(results.get('attributeNames'))
print_columns(results)
def print_report_info(columns):
print "Metadata Report Info"
if columns:
print 'Kind = %s' % columns.get('kind')
print 'Etag = %s' % columns.get('etag')
print 'Total Results = %s' % columns.get('totalResults')
def print_attributes(attributes):
if attributes:
print 'Attribute Names:'
for attribute in attributes:
print attribute
def print_columns(columns_data):
if columns_data:
print 'Columns:'
columns = columns_data.get('items', [])
for column in columns:
print
print '%15s = %35s' % ('Column ID', column.get('id'))
print '%15s = %35s' % ('Kind', column.get('kind'))
column_attributes = column.get('attributes', [])
for name, value in column_attributes.iteritems():
print '%15s = %35s' % (name, value)
참고 : metadata.list 에서 복사 한 원본 버전
C # 예제
.Net 클라이언트 라이브러리를 사용합니다.
PM> Install-Package Google.Apis.Analytics.v3
var metadataService = new AnalyticsMetaDataService(new BaseClientService.Initializer()
{
ApiKey = {Public API KEY},
ApplicationName = "Metadata api",
});
var result = Service.Metadata.Columns.List("ga").Execute();