Movatterモバイル変換


[0]ホーム

URL:


urlshortener

package
v0.257.0Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2025 License:BSD-3-ClauseImports:14Imported by:113

Details

Repository

github.com/googleapis/google-api-go-client

Links

Documentation

Overview

Package urlshortener provides access to the URL Shortener API.

For product documentation, see:https://developers.google.com/url-shortener/v1/getting_started

Creating a client

Usage example:

import "google.golang.org/api/urlshortener/v1"...ctx := context.Background()urlshortenerService, err := urlshortener.NewService(ctx)

In this example, Google Application Default Credentials are used for authentication.

For information on how to create and obtain Application Default Credentials, seehttps://developers.google.com/identity/protocols/application-default-credentials.

Other authentication options

To use an API key for authentication (note: some APIs do not support API keys), use option.WithAPIKey:

urlshortenerService, err := urlshortener.NewService(ctx, option.WithAPIKey("AIza..."))

To use an OAuth token (e.g., a user token obtained via a three-legged OAuth flow), use option.WithTokenSource:

config := &oauth2.Config{...}// ...token, err := config.Exchange(ctx, ...)urlshortenerService, err := urlshortener.NewService(ctx, option.WithTokenSource(config.TokenSource(ctx, token)))

Seehttps://godoc.org/google.golang.org/api/option/ for details on options.

Index

Constants

View Source
const (// Manage your goo.gl short URLsUrlshortenerScope = "https://www.googleapis.com/auth/urlshortener")

OAuth2 scopes used by this API.

Variables

This section is empty.

Functions

This section is empty.

Types

typeAnalyticsSnapshot

type AnalyticsSnapshot struct {// Browsers: Top browsers, e.g. "Chrome"; sorted by (descending) click// counts. Only present if this data is available.Browsers []*StringCount `json:"browsers,omitempty"`// Countries: Top countries (expressed as country codes), e.g. "US" or// "DE"; sorted by (descending) click counts. Only present if this data// is available.Countries []*StringCount `json:"countries,omitempty"`// LongUrlClicks: Number of clicks on all goo.gl short URLs pointing to// this long URL.LongUrlClicksint64 `json:"longUrlClicks,omitempty,string"`// Platforms: Top platforms or OSes, e.g. "Windows"; sorted by// (descending) click counts. Only present if this data is available.Platforms []*StringCount `json:"platforms,omitempty"`// Referrers: Top referring hosts, e.g. "www.google.com"; sorted by// (descending) click counts. Only present if this data is available.Referrers []*StringCount `json:"referrers,omitempty"`// ShortUrlClicks: Number of clicks on this short URL.ShortUrlClicksint64 `json:"shortUrlClicks,omitempty,string"`// ForceSendFields is a list of field names (e.g. "Browsers") to// unconditionally include in API requests. By default, fields with// empty values are omitted from API requests. However, any non-pointer,// non-interface field appearing in ForceSendFields will be sent to the// server regardless of whether the field is empty or not. This may be// used to include empty fields in Patch requests.ForceSendFields []string `json:"-"`// NullFields is a list of field names (e.g. "Browsers") to include in// API requests with the JSON null value. By default, fields with empty// values are omitted from API requests. However, any field with an// empty value appearing in NullFields will be sent to the server as// null. It is an error if a field in this list has a non-empty value.// This may be used to include null fields in Patch requests.NullFields []string `json:"-"`}

func (*AnalyticsSnapshot)MarshalJSON

func (s *AnalyticsSnapshot) MarshalJSON() ([]byte,error)

typeAnalyticsSummary

type AnalyticsSummary struct {// AllTime: Click analytics over all time.AllTime *AnalyticsSnapshot `json:"allTime,omitempty"`// Day: Click analytics over the last day.Day *AnalyticsSnapshot `json:"day,omitempty"`// Month: Click analytics over the last month.Month *AnalyticsSnapshot `json:"month,omitempty"`// TwoHours: Click analytics over the last two hours.TwoHours *AnalyticsSnapshot `json:"twoHours,omitempty"`// Week: Click analytics over the last week.Week *AnalyticsSnapshot `json:"week,omitempty"`// ForceSendFields is a list of field names (e.g. "AllTime") to// unconditionally include in API requests. By default, fields with// empty values are omitted from API requests. However, any non-pointer,// non-interface field appearing in ForceSendFields will be sent to the// server regardless of whether the field is empty or not. This may be// used to include empty fields in Patch requests.ForceSendFields []string `json:"-"`// NullFields is a list of field names (e.g. "AllTime") to include in// API requests with the JSON null value. By default, fields with empty// values are omitted from API requests. However, any field with an// empty value appearing in NullFields will be sent to the server as// null. It is an error if a field in this list has a non-empty value.// This may be used to include null fields in Patch requests.NullFields []string `json:"-"`}

func (*AnalyticsSummary)MarshalJSON

func (s *AnalyticsSummary) MarshalJSON() ([]byte,error)

typeService

type Service struct {BasePathstring// API endpoint base URLUserAgentstring// optional additional User-Agent fragmentUrl *UrlService// contains filtered or unexported fields}

funcNewdeprecated

func New(client *http.Client) (*Service,error)

New creates a new Service. It uses the provided http.Client for requests.

Deprecated: please use NewService instead.To provide a custom HTTP client, use option.WithHTTPClient.If you are using google.golang.org/api/googleapis/transport.APIKey, use option.WithAPIKey with NewService instead.

funcNewServiceadded inv0.3.0

func NewService(ctxcontext.Context, opts ...option.ClientOption) (*Service,error)

NewService creates a new Service.

typeStringCount

type StringCount struct {// Count: Number of clicks for this top entry, e.g. for this particular// country or browser.Countint64 `json:"count,omitempty,string"`// Id: Label assigned to this top entry, e.g. "US" or "Chrome".Idstring `json:"id,omitempty"`// ForceSendFields is a list of field names (e.g. "Count") to// unconditionally include in API requests. By default, fields with// empty values are omitted from API requests. However, any non-pointer,// non-interface field appearing in ForceSendFields will be sent to the// server regardless of whether the field is empty or not. This may be// used to include empty fields in Patch requests.ForceSendFields []string `json:"-"`// NullFields is a list of field names (e.g. "Count") to include in API// requests with the JSON null value. By default, fields with empty// values are omitted from API requests. However, any field with an// empty value appearing in NullFields will be sent to the server as// null. It is an error if a field in this list has a non-empty value.// This may be used to include null fields in Patch requests.NullFields []string `json:"-"`}

func (*StringCount)MarshalJSON

func (s *StringCount) MarshalJSON() ([]byte,error)

typeUrl

type Url struct {// Analytics: A summary of the click analytics for the short and long// URL. Might not be present if not requested or currently unavailable.Analytics *AnalyticsSummary `json:"analytics,omitempty"`// Created: Time the short URL was created; ISO 8601 representation// using the yyyy-MM-dd'T'HH:mm:ss.SSSZZ format, e.g.// "2010-10-14T19:01:24.944+00:00".Createdstring `json:"created,omitempty"`// Id: Short URL, e.g. "http://goo.gl/l6MS".Idstring `json:"id,omitempty"`// Kind: The fixed string "urlshortener#url".Kindstring `json:"kind,omitempty"`// LongUrl: Long URL, e.g. "http://www.google.com/". Might not be// present if the status is "REMOVED".LongUrlstring `json:"longUrl,omitempty"`// Status: Status of the target URL. Possible values: "OK", "MALWARE",// "PHISHING", or "REMOVED". A URL might be marked "REMOVED" if it was// flagged as spam, for example.Statusstring `json:"status,omitempty"`// ServerResponse contains the HTTP response code and headers from the// server.googleapi.ServerResponse `json:"-"`// ForceSendFields is a list of field names (e.g. "Analytics") to// unconditionally include in API requests. By default, fields with// empty values are omitted from API requests. However, any non-pointer,// non-interface field appearing in ForceSendFields will be sent to the// server regardless of whether the field is empty or not. This may be// used to include empty fields in Patch requests.ForceSendFields []string `json:"-"`// NullFields is a list of field names (e.g. "Analytics") to include in// API requests with the JSON null value. By default, fields with empty// values are omitted from API requests. However, any field with an// empty value appearing in NullFields will be sent to the server as// null. It is an error if a field in this list has a non-empty value.// This may be used to include null fields in Patch requests.NullFields []string `json:"-"`}

func (*Url)MarshalJSON

func (s *Url) MarshalJSON() ([]byte,error)

typeUrlGetCall

type UrlGetCall struct {// contains filtered or unexported fields}

func (*UrlGetCall)Context

func (c *UrlGetCall) Context(ctxcontext.Context) *UrlGetCall

Context sets the context to be used in this call's Do method. Anypending HTTP request will be aborted if the provided context iscanceled.

func (*UrlGetCall)Do

func (c *UrlGetCall) Do(opts ...googleapi.CallOption) (*Url,error)

Do executes the "urlshortener.url.get" call.Exactly one of *Url or error will be non-nil. Any non-2xx status codeis an error. Response headers are in either*Url.ServerResponse.Header or (if a response was returned at all) inerror.(*googleapi.Error).Header. Use googleapi.IsNotModified to checkwhether the returned error was because http.StatusNotModified wasreturned.

func (*UrlGetCall)Fields

func (c *UrlGetCall) Fields(s ...googleapi.Field) *UrlGetCall

Fields allows partial responses to be retrieved. Seehttps://developers.google.com/gdata/docs/2.0/basics#PartialResponsefor more information.

func (*UrlGetCall)Header

func (c *UrlGetCall) Header()http.Header

Header returns an http.Header that can be modified by the caller toadd HTTP headers to the request.

func (*UrlGetCall)IfNoneMatch

func (c *UrlGetCall) IfNoneMatch(entityTagstring) *UrlGetCall

IfNoneMatch sets the optional parameter which makes the operationfail if the object's ETag matches the given value. This is useful forgetting updates only after the object has changed since the lastrequest. Use googleapi.IsNotModified to check whether the responseerror from Do is the result of In-None-Match.

func (*UrlGetCall)Projection

func (c *UrlGetCall) Projection(projectionstring) *UrlGetCall

Projection sets the optional parameter "projection": Additionalinformation to return.

Possible values:

"ANALYTICS_CLICKS" - Returns only click counts."ANALYTICS_TOP_STRINGS" - Returns only top string counts."FULL" - Returns the creation timestamp and all available

analytics.

typeUrlHistory

type UrlHistory struct {// Items: A list of URL resources.Items []*Url `json:"items,omitempty"`// ItemsPerPage: Number of items returned with each full "page" of// results. Note that the last page could have fewer items than the// "itemsPerPage" value.ItemsPerPageint64 `json:"itemsPerPage,omitempty"`// Kind: The fixed string "urlshortener#urlHistory".Kindstring `json:"kind,omitempty"`// NextPageToken: A token to provide to get the next page of results.NextPageTokenstring `json:"nextPageToken,omitempty"`// TotalItems: Total number of short URLs associated with this user (may// be approximate).TotalItemsint64 `json:"totalItems,omitempty"`// ServerResponse contains the HTTP response code and headers from the// server.googleapi.ServerResponse `json:"-"`// ForceSendFields is a list of field names (e.g. "Items") to// unconditionally include in API requests. By default, fields with// empty values are omitted from API requests. However, any non-pointer,// non-interface field appearing in ForceSendFields will be sent to the// server regardless of whether the field is empty or not. This may be// used to include empty fields in Patch requests.ForceSendFields []string `json:"-"`// NullFields is a list of field names (e.g. "Items") to include in API// requests with the JSON null value. By default, fields with empty// values are omitted from API requests. However, any field with an// empty value appearing in NullFields will be sent to the server as// null. It is an error if a field in this list has a non-empty value.// This may be used to include null fields in Patch requests.NullFields []string `json:"-"`}

func (*UrlHistory)MarshalJSON

func (s *UrlHistory) MarshalJSON() ([]byte,error)

typeUrlInsertCall

type UrlInsertCall struct {// contains filtered or unexported fields}

func (*UrlInsertCall)Context

Context sets the context to be used in this call's Do method. Anypending HTTP request will be aborted if the provided context iscanceled.

func (*UrlInsertCall)Do

func (c *UrlInsertCall) Do(opts ...googleapi.CallOption) (*Url,error)

Do executes the "urlshortener.url.insert" call.Exactly one of *Url or error will be non-nil. Any non-2xx status codeis an error. Response headers are in either*Url.ServerResponse.Header or (if a response was returned at all) inerror.(*googleapi.Error).Header. Use googleapi.IsNotModified to checkwhether the returned error was because http.StatusNotModified wasreturned.

func (*UrlInsertCall)Fields

func (c *UrlInsertCall) Fields(s ...googleapi.Field) *UrlInsertCall

Fields allows partial responses to be retrieved. Seehttps://developers.google.com/gdata/docs/2.0/basics#PartialResponsefor more information.

func (*UrlInsertCall)Header

func (c *UrlInsertCall) Header()http.Header

Header returns an http.Header that can be modified by the caller toadd HTTP headers to the request.

typeUrlListCall

type UrlListCall struct {// contains filtered or unexported fields}

func (*UrlListCall)Context

func (c *UrlListCall) Context(ctxcontext.Context) *UrlListCall

Context sets the context to be used in this call's Do method. Anypending HTTP request will be aborted if the provided context iscanceled.

func (*UrlListCall)Do

Do executes the "urlshortener.url.list" call.Exactly one of *UrlHistory or error will be non-nil. Any non-2xxstatus code is an error. Response headers are in either*UrlHistory.ServerResponse.Header or (if a response was returned atall) in error.(*googleapi.Error).Header. Use googleapi.IsNotModifiedto check whether the returned error was becausehttp.StatusNotModified was returned.

func (*UrlListCall)Fields

func (c *UrlListCall) Fields(s ...googleapi.Field) *UrlListCall

Fields allows partial responses to be retrieved. Seehttps://developers.google.com/gdata/docs/2.0/basics#PartialResponsefor more information.

func (*UrlListCall)Header

func (c *UrlListCall) Header()http.Header

Header returns an http.Header that can be modified by the caller toadd HTTP headers to the request.

func (*UrlListCall)IfNoneMatch

func (c *UrlListCall) IfNoneMatch(entityTagstring) *UrlListCall

IfNoneMatch sets the optional parameter which makes the operationfail if the object's ETag matches the given value. This is useful forgetting updates only after the object has changed since the lastrequest. Use googleapi.IsNotModified to check whether the responseerror from Do is the result of In-None-Match.

func (*UrlListCall)Projection

func (c *UrlListCall) Projection(projectionstring) *UrlListCall

Projection sets the optional parameter "projection": Additionalinformation to return.

Possible values:

"ANALYTICS_CLICKS" - Returns short URL click counts."FULL" - Returns short URL click counts.

func (*UrlListCall)StartToken

func (c *UrlListCall) StartToken(startTokenstring) *UrlListCall

StartToken sets the optional parameter "start-token": Token forrequesting successive pages of results.

typeUrlService

type UrlService struct {// contains filtered or unexported fields}

funcNewUrlService

func NewUrlService(s *Service) *UrlService

func (*UrlService)Get

func (r *UrlService) Get(shortUrlstring) *UrlGetCall

Get: Expands a short URL or gets creation time and analytics.

func (*UrlService)Insert

func (r *UrlService) Insert(url *Url) *UrlInsertCall

Insert: Creates a new short URL.

func (*UrlService)List

func (r *UrlService) List() *UrlListCall

List: Retrieves a list of URLs shortened by a user.

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp