Git Product home page Git Product logo

google-api-go-client's Introduction

Google APIs Client Library for Go

Getting Started

$ go get google.golang.org/api/tasks/v1
$ go get google.golang.org/api/moderator/v1
$ go get google.golang.org/api/urlshortener/v1
... etc ...

and using:

package main

import (
        "context"
        "net/http"

        "google.golang.org/api/urlshortener/v1"
)

func main() {
        ctx := context.Background()
        svc, err := urlshortener.NewService(ctx)
        // ...
}

Status

Go Reference

These are auto-generated Go libraries from the Google Discovery Service's JSON description files.

Due to the auto-generated nature of this collection of libraries they may contain breaking changes from one release to the next. The generator itself and the code it produces are considered beta for this reason.

These client libraries are officially supported by Google. However, the libraries are considered complete and are in maintenance mode. This means that we will address critical bugs and security issues but will not add any new features.

If you're working with Google Cloud Platform APIs such as Datastore or Pub/Sub, please use the Cloud Client Libraries for Go instead. These are the new and idiomatic Go libraries targeted specifically at Google Cloud Platform Services.

Authorization

By default, each API will use Google Application Default Credentials for authorization credentials used in calling the API endpoints. This will allow your application to run in many environments without requiring explicit configuration.

// import "google.golang.org/api/sheets/v4"
client, err := sheets.NewService(ctx)

To authorize using a JSON key file, pass option.WithCredentialsFile to the NewService function of the desired package. For example:

client, err := sheets.NewService(ctx, option.WithCredentialsFile("path/to/keyfile.json"))

You can exert more control over authorization by using the golang.org/x/oauth2 package to create an oauth2.TokenSource. Then pass option.WithTokenSource to the NewService function:

tokenSource := ...
svc, err := sheets.NewService(ctx, option.WithTokenSource(tokenSource))

More information

For some more information related to all of the generated clients please read through our package documentation.

google-api-go-client's People

Contributors

andyrzhao avatar bradfitz avatar brennaepp avatar broady avatar campoy avatar codyoss avatar dependabot[bot] avatar dsymonds avatar enocom avatar gmlewis avatar googleapis-publisher avatar jba avatar jeanbza avatar mattwhisenhunt avatar mcgreevy avatar mohanli-ml avatar noahdietz avatar okdave avatar proppy avatar quartzmo avatar rakyll avatar release-please[bot] avatar renovate-bot avatar shinfan avatar shollyman avatar tritone avatar vchudnov-g avatar xmenxk avatar yoshi-automation avatar zombiezen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

google-api-go-client's Issues

Expose errors field in googleapi.Error

[email protected] on 28 Nov 2012 at 3:22:

The Error type of googleapi only exposes code and message. But the errors field 
is needed in order to get the reason so that the recommended exponential 
backoff can be implemented:

https://developers.google.com/drive/handle-errors#implementing_exponential_backo
ff

Setting RelativeDateRange to nothing may be strange or need documentation

[email protected] on 8 Oct 2013 at 4:15:

What steps will reproduce the problem?
1. Create a report in the UI with a Relative Date Range
2. Attempt to use start and end date in the API
3. Had to set RelativeDateRange = "  " (blank spaces) to avoid error

example:

report.Criteria.DateRange.StartDate = startDate
    report.Criteria.DateRange.EndDate = endDate
    report.Criteria.DateRange.RelativeDateRange = "    " // Relative date range cannot be set if using start & end dates...

    reportPatch := dfareportingService.Reports.Patch(profileId, reportId, report)
    report, err = reportPatch.Do()


What is the expected output? What do you see instead?
I would expect to be able to set RelativeDateRange = "" or have a reset to 
nothing mechanism

What version of the product are you using? On what operating system?
Go API 1.3

Please provide any additional information below.

go mirror v1 link is broken (using go mirror example app)

colabug on 9 Dec 2013 at 11:30:

What steps will reproduce the problem?
1. Download example project: https://github.com/googleglass/mirror-quickstart-go
2. Configure the example using "appcfg.py --oauth2 update ."

What is the expected output? What do you see instead?
Should build the project, but fails to find the no longer existing url: 
code.google.com/p/google-api-go-client/mirror/v1. Error message:

Compile failed:
2013/12/09 15:21:07 go-app-builder: build timing: 1×6g (33.43696ms total), 
0×gopack (0 total), 0×6l (0 total)
2013/12/09 15:21:07 go-app-builder: failed running 6g: exit status 1
attachment.go:21: can't find import: 
"code.google.com/p/google-api-go-client/mirror/v1"

What version of the product are you using? On what operating system?
go version: go1.1.2 (appengine-1.8.8) darwin/amd64
Mac OSX 10.7.5

Please provide any additional information below.
Has this moved or is there a different way to access now?

Folder 'examples' improperly named

[email protected] on 3 Jan 2013 at 2:44:

Apparently, the name of the folder 'examples' is supposed to be 'go-api-demo'. 
Currently, an executable named 'examples' in the bin folder describes its usage 
as:

Usage: go-api-demo <api-demo-name> [api name args]

drive/v2: FileExportLinks is an empty struct

imgx64 on 18 Oct 2012 at 8:46:

In the Drive API, FileExportLinks doesn't get populated with exportLinks 
because it's an empty struct[1]. Changing it to a "map[string]string", and 
changing File.ExportLinks from "*FileExportLinks" to "FileExportLinks" allows 
it to be populated properly.

[1] 
http://code.google.com/p/google-api-go-client/source/browse/drive/v2/drive-gen.g
o?spec=svnf2d5f0fc941a1e1ae50b1cd65371d1fb474f9cbb&r=677f7744ee455af05a37828bd26
575b3025a8364#532

Support nested methods in the API generator

[email protected] on 11 Apr 2013 at 11:50:

What steps will reproduce the problem?
1. Try to generate a client library for an API with nested resources and 
methods (e.g books/v1)
2. Generated client only contains methods for first level resource: 
books.volumes.list, etc.
3. Generated client does not contain methods for deeper level resources: 
books.bookshelves.volumes.list

What is the expected output? What do you see instead?

The generated client should contain methods for all the API methods, instead, 
it only contains method for first level resources.

What version of the product are you using? On what operating system?

Latest version from the repo.

Please provide any additional information below.

Example discovery doc available at: 
https://www.googleapis.com/discovery/v1/apis/books/v1/rest

Example ignores error

n13m3y3r on 12 Mar 2013 at 12:26:

Might be wise to not teach people to ignore errors:

        service, _ := compute.New(client)
        projectId := argv[0]
        instanceName := argv[1]

From:

http://code.google.com/p/google-api-go-client/source/browse/examples/compute.go

Calendar Events.List returns 404 error

KerbyShedden on 13 May 2012 at 4:16:

What steps will reproduce the problem?

I use this Go code in my application:

## t is an oauth.transport that has been authenticated with tokens
svc,_ := calendar.New(t.Client())
A,e := svc.Events.List(cal_id).MaxResults(10).SingleEvents(true).Do()

where cal_id is a string containing a Google calendar id of the form 
#####@group.calendar.google.com

What is the expected output? What do you see instead?

I expect A.Items to contain some calendar events, instead I get a 404 error.

What version of the product are you using? On what operating system?

Appengine API and google-api-go-client downloaded from repositories within last 
week.  Using calendar v3 interfaces.


Please provide any additional information below.

If I change one line in `func (c *EventsListCall) Do() (*Events, error)` in the 
API source code things work.

I changed

urls = strings.Replace(urls, "{calendarId}", cleanPathString(c.calendarId), 1)

to

urls = strings.Replace(urls, "{calendarId}", c.calendarId, 1)

and it works.

It appears that cleanPathString removes the . characters from the calendar id 
so instead of #####@group.calendar.google.com we get 
####@groupcalendargooglecom, hence the 404.

Support Google Spreadsheet

philip142au on 2 Aug 2012 at 2:00:

Please support Google Spreadsheet API so that I can get and put data into a 
spreadsheet in Google Docs. Thanks! Philip

CloudStorage API cannot specify metadata

graham.miller on 28 Aug 2012 at 6:41:


The documentation at 
https://developers.google.com/storage/docs/json_api/v1/objects/insert indicates 
that there should be a metadata property of the object insert method, that is 
"User-provided metadata, in key/value pairs."

The relevant field in the "Object" definition is as follows:

        // Metadata: User-provided metadata, in key/value pairs.
        Metadata *ObjectMetadata `json:"metadata,omitempty"`

However, ObjectMetadata is defined as follows:

type ObjectMetadata struct {
}

Shouldn't this be a "map[string]string" or something else that would allow you 
to actually send/receive metadata?

Fusion Table support

DonovanHide on 12 Oct 2013 at 1:30:

I'd like to use the Fusion Tables API, but the tool has a hard-coded fail for 
that particular API:

https://code.google.com/p/google-api-go-client/source/browse/google-api-go-gener
ator/gen.go#156

Is there any more information on why the codegen fails and can I help with the 
fix?

Plus api, Person struct doesn't include email

[email protected] on 4 Aug 2013 at 7:52:

What steps will reproduce the problem?
1. Look at source of plus/v1/plus-gen.go

What is the expected output? What do you see instead?
Expected to have email field, as defined in the G+ API here: 
https://developers.google.com/+/api/latest/people

What version of the product are you using? On what operating system?
Latest verson


recent change has client make bad URLs

[email protected] on 3 Jun 2013 at 5:39:

Change 49979a5f1445 introduces behavior that has the client make request like 
this:

POST //www.googleapis.com/upload/drive/v2/files?uploadType=multipart&alt=json 
HTTP/1.1
Host: www.googleapis.com
User-Agent: google-api-go-client/0.5
Content-Length: 23301
Authorization: Bearer redacted
Content-Type: multipart/related; 
boundary=c18fb9c5303d177b9679b4c9a81b68442af746f6d0655c75fa57d001d1b8

AFAIK, it's not valid to say "VERB //host/path".

Errors from server not handled well

[email protected] on 13 Dec 2013 at 3:45:

I suspect this is true about many/all services, but my code looks something 
like this:

        _, err = service.Objects.Insert(bucket, obj).Media(f).Do()

Where service is a "storage service" instance.  This is all well and good until 
the server returns an error.  The error comes through as an XML body of the 
HTTP response.  Like this:

<?xml version='1.0' 
encoding='UTF-8'?><Error><Code>NoSuchBucket</Code><Message>The specified bucket 
does not exist.</Message></Error>

The google-api-go-client tries to parse this as a valid "insert" response, and 
gets confused, giving something along the lines of:

googleapi: got HTTP response code 404 and error reading body: invalid character 
'<' looking for beginning of value: error uploading file

It would be nice if the error returned contained more information about what 
the server says the error is.

FileInsertCall.Convert(true) won't work

sunixm on 4 Jun 2013 at 3:33:

What steps will reproduce the problem?
1. Files.Insert(&drive.File{Title: 
"file.docx"}).Convert(true).Media(reader).Do()

What is the expected output? What do you see instead?
file.docx being uploaded and convert to Google Drive format
but instead only the file name appears in Google Drive, with on content

What version of the product are you using? On what operating system?
the lastest go client library: tag: 5d818df85e09, date:2013.5.28
Windows Xp 

some integers need to be serialized as strings

[email protected] on 25 Aug 2011 at 9:04:

If the JSON describes an API parameter or property as having type=="string" but 
format=="int64", etc, it needs to be un/marshalled as a string.

(This is because JavaScript only has doubles and 52 bits of integer precission)

Until this is fixed, some parameters won't work.  Parameters that go in the URL 
are fine, but ones that are in JSON bodies probably won't work.

Related:
http://codereview.appspot.com/4918051/

Update datastore API to v1beta2

[email protected] on 28 Sep 2013 at 3:48:

The new version of the cloud datastore API is what's currently documented at 
https://developers.google.com/datastore/docs/apis/v1beta2/, and returns 
significantly different response formats from v1beta1 (specifically on the 
entity properties).

Additionally, the current version of the API doesn't handle said properties 
correctly (they are always blank). I've attached an updated version of the 
generated code that correctly handles the responses from v1beta1. See the 
Entity, EntityProperty, and Value structs for changed areas.

Thanks,
Alex

Support resumable media upload

[email protected] on 12 Nov 2012 at 4:15:

The library only supports the "simple" upload protocol. It would be very good 
to support "resumable" so that large files can be reliably uploaded.

https://developers.google.com/discovery/v1/using#discovery-doc-methods-mediauplo
ad

Some types are generated as blank, thus missing valuable data from the response

shazow on 7 Sep 2013 at 10:53:

Specifically, I believe this applies to types which should be 
map[string]string{} or similar.

Examples:

analytics.GaDataTotalsForAllResults 
https://code.google.com/p/google-api-go-client/source/browse/analytics/v3/analyt
ics-gen.go#866

analytics.McfDataTotalsForAllResults
https://code.google.com/p/google-api-go-client/source/browse/analytics/v3/analyt
ics-gen.go#1189

analytics.ColumnAttributes: 
https://code.google.com/p/google-api-go-client/source/browse/analytics/v3/analyt
ics-gen.go#31

In JSON, the result (for GaDataTotalsForAllResults, for example) looks like 
this:

        ...
        "totalsForAllResults": {
            "ga:visits": "9978"
        },
        ...

But in the struct type, it just ends up being a pointer to a blank struct and 
the map is lost.

freebase: MqlreadCall.Do() is useless

dathead on 4 Mar 2013 at 8:50:

What steps will reproduce the problem?
1. call := client.Mqlread(query)
2. err := call.Do()
3. ... Where are the results?

What is the expected output? What do you see instead?
A return value containing the response bytes so that I can use encoding/json to 
decode them would be nice.  Instead the result appears to be thrown away.

What version of the product are you using? On what operating system?
I am looking at the head revision (43ee29020514).

Please provide any additional information below.

Server to server authentication examples

neoyagami on 14 Oct 2013 at 5:08:

Hi.
I want to know y there are more examples for Server to Server Oauth2.
i need my server internally keeps feeding from analytics data but the standard 
auth access only let me get a 1 hour permission.

can be the documentation be more specific in how to make this possible?



HTTP headers for .go suggest save-to-disk binary downloaded

ralph.corderoy on 28 Jul 2013 at 10:08:

The HTTP headers for a .go cause this browser to want to save it to disk
whereas a .json, for example, can be opened with an application.
Extracts from "curl -sSI":

    http://google-api-go-client.googlecode.com/hg/urlshortener/v1/urlshortener-api.json
        Content-Type: application/json; charset=ISO-8859-1
        Content-Disposition: attachment

    http://google-api-go-client.googlecode.com/hg/urlshortener/v1/urlshortener-gen.go
        Content-Type: application/octet-stream

Assuming it's a project-configuration issue, I'm opening it on 
google-api-go-client.

Please fix *.go in examples directory to work with v1beta13 api

tjyang2001 on 18 Nov 2012 at 2:39:

What steps will reproduce the problem?
1.
2.
3.

What do you see instead?

TJYANG-MBA:examples tjyang$ pwd;date;go version
/Users/tjyang/gocode/google-api-go-client/examples
Sat Nov 17 20:29:23 CST 2012
go version go1.0.2
TJYANG-MBA:examples tjyang$ go build -x compute.go
WORK=/var/folders/b5/fvmddjbn7pz8wh90gxdx4h8w0000gp/T/go-build981563320
mkdir -p $WORK/command-line-arguments/_obj/
cd /Users/tjyang/gocode/google-api-go-client/examples
/usr/local/go/pkg/tool/darwin_amd64/6g -o 
$WORK/command-line-arguments/_obj/_go_.6 -p command-line-arguments -D 
_/Users/tjyang/gocode/google-api-go-client/examples -I $WORK ./compute.go
# command-line-arguments
./compute.go:13: undefined: registerDemo
TJYANG-MBA:examples tjyang$ 
TJYANG-MBA:examples tjyang$ go build -x compute.go
WORK=/var/folders/b5/fvmddjbn7pz8wh90gxdx4h8w0000gp/T/go-build981563320
mkdir -p $WORK/command-line-arguments/_obj/
cd /Users/tjyang/gocode/google-api-go-client/examples
/usr/local/go/pkg/tool/darwin_amd64/6g -o 
$WORK/command-line-arguments/_obj/_go_.6 -p command-line-arguments -D 
_/Users/tjyang/gocode/google-api-go-client/examples -I $WORK ./compute.go
# command-line-arguments
./compute.go:13: undefined: registerDemo
TJYANG-MBA:examples tjyang$ 


What version of the product are you using? On what operating system?

TJYANG-MBA:examples tjyang$ go version
go version go1.0.2
TJYANG-MBA:examples tjyang$ 

Darwin TJYANG-MBA.local 11.4.2 Darwin Kernel Version 11.4.2: Thu Aug 23 
16:25:48 PDT 2012; root:xnu-1699.32.7~1/RELEASE_X86_64 x86_64


Please provide any additional information below.

Is my go version too new ? I remembered I got it compiled one time perhaps 
using order version of go with v1beta12 api library.

Loading BigQuery data by sending a POST request - minimal example fails

gavaletz on 2 May 2013 at 2:19:

What steps will reproduce the problem?
1. Setup BiqQuery in API console
2. Create client ID for installed application
3. Try to POST data to BigQuery (http://goo.gl/pG14W)

What is the expected output? What do you see instead?
"OK"

And then find our shiny new table in BigQuery

"main:log2bq:googleapi: Error 400: Bad Request"

What version of the product are you using? On what operating system?
Go working from tip
google-api-go-client working from tip
Linux x86_64

Please provide any additional information below.

I am providing a minimal example, but to be honest I am not 100% sure the bug 
is in the google-api-go-client code or if there is a problem with BigQuery.  I 
tried using the client-api and created the request "by hand" and keep getting 
the same results.  The response body returned by the BigQuery API is very 
helpful:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "badRequest",
    "message": "Bad Request"
   }
  ],
  "code": 400,
  "message": "Bad Request"
 }

It might as well just say "PC LOAD LETTER".  I know it is not a problem with 
authentication because I can put in a bad credentials and get a different (more 
specific) error.

Hopefully this minimal example can be made to work and help with checking off 
https://code.google.com/p/google-api-go-client/issues/detail?id=3.

adsense mgmt api dashes in adClientId

Brandon.J.Thomson on 28 Nov 2011 at 11:38:

I think there is an issue with the adsense management api.

adClientId is a string like "ca-pub-23949832498" which contains dashes, but 
cleanPathString seems to remove those dashes which causes a 404 error.

ie svc.Urlchannels.List("ca-pub-23949832498") makes a url like 
https://www.googleapis.com/adsense/v1/adclients/capub23949832498/... when it 
should be
https://www.googleapis.com/adsense/v1/adclients/ca-pub-23949832498/...

When I changed the code (adsense-gen.go:749) from
urls = strings.Replace(urls, "{adClientId}", cleanPathString(c.adClientId), 1)
to
urls = strings.Replace(urls, "{adClientId}", c.adClientId, 1)
the call worked as expected.

By the way this code is very nice to use, thank you very much :)

DNS lookup fails after a number of hours

hokapoka.com on 5 Jan 2012 at 9:32:

What steps will reproduce the problem?
1. Create a simple Google plus consumer that receives updates via a time.Ticker 
every 5 mins. 

2. Request the ActivitiesService.List() with any valid G+ profile id and 
"public" for the collection

3. Run the service for 6+ hours


What is the expected output? What do you see instead?

I expect the service to continue to run until I stop the process, however the 
consumer will work for roughly 6 hours flawlessly and then the consumer fails 
with an error message : 

"Get 
https://www.googleapis.com/plus/v1/people/<USER_ID>/activities/public?alt=json: 
dial tcp accounts.google.com:443: lookup accounts.google.com: no such host"

If I restart the process and the sequence repeats, that's to say it's able to 
retrive the Activity stream again and after about 6+ hours it fails with the 
same error message.


What version of the product are you using? On what operating system?

I'm using the current release branch of go with the latest version of the 
google-api-go-client.  

This is currently on a OSx Lion x64 machine. 


Please provide any additional information below.

I have checked the API usage on here : 
https://code.google.com/apis/console/b/0/ and it's never reached even 50% of 
allowed quota so it's not that the service is blocking the connection because 
of that. 

This behaviour has been consistant for the past 2 weeks.


Support for Standard Query Parameters (fields, quotaUser, userIp, etc) in Google APIs

shazow on 5 Sep 2013 at 4:40:

Most (if not all) Google API's support standard query parameters, such as ones 
documented here:
https://developers.google.com/discovery/v1/parameters
https://developers.google.com/drive/query-parameters
https://developers.google.com/analytics/devguides/reporting/realtime/v3/paramete
rs
Etc.

There doesn't seem to be a way to set these using the google-api-go-client 
library.

Would be great if there was native support for these fields. Perhaps it would 
make sense letting the user set arbitrary fields to the opt_ field map, for 
future workarounds to such limitations?

Related bugs:
#5 https://code.google.com/p/google-api-go-client/issues/detail?id=5
#38 https://code.google.com/p/google-api-go-client/issues/detail?id=38

I would consider this bug to be a superset of the other two.

Thanks!

[FR] Support the discovery document "supportsMediaDownload" flag

[email protected] on 25 Oct 2012 at 11:11:

Google APIs can set a flag in their discovery document to clients know that a 
method supports the "?alt=media" query parameter to download media content 
instead of JSON metadata.

An example can be seen on the storage.objects.get endpoint from the Cloud 
Storage API:

    "get": {
     "id": "storage.objects.get",
     "path": "b/{bucket}/o/{object}",
     "httpMethod": "GET",
     "description": "Retrieves objects or their associated metadata.",
     "parameters": {
      "bucket": {
       "type": "string",
       "description": "Name of the bucket in which the object resides.",
       "required": true,
       "location": "path"
      },
      "object": {
       "type": "string",
       "description": "Name of the object.",
       "required": true,
       "location": "path"
      },
      "projection": {
       "type": "string",
       "description": "Set of properties to return. Defaults to no_acl.",
       "enum": [
        "full",
        "no_acl"
       ],
       "enumDescriptions": [
        "Include all properties.",
        "Omit the acl property."
       ],
       "location": "query"
      }
     },
     "parameterOrder": [
      "bucket",
      "object"
     ],
     "response": {
      "$ref": "Object"
     },
     "scopes": [
      "https://www.googleapis.com/auth/devstorage.full_control",
      "https://www.googleapis.com/auth/devstorage.read_only",
      "https://www.googleapis.com/auth/devstorage.read_write"
     ],
     "supportsMediaDownload": true
    }

[from https://www.googleapis.com/discovery/v1/apis/storage/v1beta1/rest]

If such flag is set, the generator could generate a Download method that would 
set the "?alt=" query parameter to "media" and return an http.Response object 
or a simpler object containing:
  * an io.Reader for the content.
  * a string for the content-type.

This makes it easier for client to download content instead of manually 
building URLs and HTTP requests.


Add field selectors

[email protected] on 9 Aug 2013 at 10:53:

`fields` query param allows API backend to trim down the returning entity, 
valuable for working with resources with large number of attributes. Also note 
that some APIs ignore unnecessary calls that may improve performance.

func (c *XCall) Fields(fields string) *XCall {
    c.opt_["fields"] = fields
    return c
}

Sample for drive.files.list with `items/id,nextPageToken`:
GET https://www.googleapis.com/drive/v2/files?fields=items%2Fid%2CnextPageToken

Support batch requests

[email protected] on 16 Apr 2013 at 3:50:

For a description of how batching works, see e.g.
https://developers.google.com/coordinate/v1/batch

It seems to be something that works on many if not all APIs.

I haven't decided exactly what the best way to handle it would be, but it seems 
like one might be able to construct an http.Client which transparently did 
batching.  When a Dial is done on the transport, it returns a conn whose other 
end is actually a local piece of code reading the HTTP request and adding it to 
the batch; then when the pseudo-Client's "Release" method (or similar) is 
called, all queued requests are assembled, sent, and then distributed back out 
to the waiting net.Conns.  Magic :).

The less magical way would be to generate additional APIs along the lines of

func (WhateverCall) AddTo(b Batch) (*Result, *error) { ... }

and then the Batch would have a Do which assembled the requests, decoded the 
responses into the pointers, etc.  I'm not sure how I feel about the 
pointer-to-error, though.

The up-shot of the first is that you can e.g. request a list of IDs, spin up a 
goroutine for each, and then every 100ms or so release the batch queries until 
all of the goroutines are done doing their work.  They would see it as a 
sequential request.  The up-shot of the second is that the batching is explicit 
in the code, but it seems a lot harder to use.

I might play around with this at some point if you think it's a good idea.

Calendar.Events.Insert accepts "default" as calendarId, but returns 404

[email protected] on 30 Mar 2013 at 5:38:

# What steps will reproduce the problem?

1. Create a dummy Event struct:

  eventStart := calendar.EventDateTime {
    DateTime: "2013-03-30T02:10:45-03:00",
  }

  eventEnd := calendar.EventDateTime {
    DateTime: "2013-03-30T02:20:45-03:00",
  }

  eventNew := calendar.Event {
    Summary: "Test event",
    Start: &eventStart,
    End: &eventEnd,
  }

2. Attempt using Calendar.Events.Insert to insert it into the default calendar:

  calendarEvent, err := calendarApi.Events.Insert("@default", &eventNew).Do();

3. err says:

  googleapi: Error 404: Not Found


# What is the expected output? What do you see instead?

Expected output: successfully created event, inside the default calendar.


# What version of the product are you using? On what operating system?

go1.0.3
Mac OS X 10.8.2
google-api-go-client latest (53a9f7c3169a)

support global fields

[email protected] on 11 Oct 2011 at 7:56:

Selector specifying which fields to include in a partial response

e.g. from blogger json:

  "fields": {
   "type": "string",
   "description": "Selector specifying which fields to include in a partial response.",
   "location": "query"
  },


http://googlecode.blogspot.com/2011/07/lightning-fast-performance-tips-for.html

Support for push notifications

imjasonh on 22 May 2013 at 3:25:

API Push Notifications were recently announced and demoed at I/O 
(http://www.youtube.com/watch?v=NlZZghBnfdM)

It would be great to have some of these common parts done by Go library code, 
so a developer could skip having to rewrite the protocol code each time.

If the Discovery document exposes the requisite information, Go code could be 
generated to allow developers to write something like:

svc.Playlists.Watch(playlistId).Do()
svc.Playlists.HandleNotification("/notifications", func(w http.ResponseWriter, 
r *http.Request, p youtube.Playlist, s common.StateChange) {
    // Do something with the updated playlist
    // stateChange is an enum describing whether it's an insertion, update, or deletion operation
})

This would register a http.HandleFunc that parses the request headers to 
determine the StateChange being described, and decode the JSON body into the 
Playlist, and pass it to the func.

I'm not sure if Discovery documents expose enough information for this to be 
possible, or if this is a good API surface, but it's worth looking into at 
least.

An array of floats represented as strings causes json decoding to fail

[email protected] on 26 Aug 2013 at 11:11:

What steps will reproduce the problem?
When the json of a field in the api is like this:
"schemas": {
 "Person": {
"scores": {
  "type": "array",
  "items": {
     "type": "string",
     "format": "float64",
   }
}
}
}

The generated Go struct looks like this:
Person {
   Scores []float64 `json:"scores,omitempty"`
}

Then when the api returns something like 
{ "scores": ["1234", "234", "234"] }
The json decoder fails because it's expecting an array of float64s, but its 
receiving an array of strings.


This failure can be seen here:
http://play.golang.org/p/TOMqS10VMo

Support 'dataWrapper' feature for received data

[email protected] on 8 Jul 2012 at 10:47:

What steps will reproduce the problem?
1. Make a request for Location or LocationFeed against the Latitude v1 API

What is the expected output? What do you see instead?
The API call returns the zero value for any requested resource.

What version of the product are you using? On what operating system?
Revision: f49294b59cd7

Please provide any additional information below.

The Latitude v1 API has the 'dataWrapper' feature. The Go API client seems to 
support this feature when encoding data to send to an API, but not (unless I've 
misunderstood what's going on) when receiving data from an API.

I always get the zero value when making a request against this API because I'm 
receiving JSON of the form:

  {"data":{"kind":"...","items":"..."}}

rather than

  {"kind":"...","items":"..."}

The code generated by google-api-go-generator seems to expect the latter form, 
event if the 'dataWrapper' feature is enabled.

I'm using this slightly ugly patch to work around this - I've only tried it 
with the Latitude API, so it may not work elsewhere:


diff -r f49294b59cd7 google-api-go-generator/gen.go
--- a/google-api-go-generator/gen.go    Fri May 11 15:38:15 2012 +1000
+++ b/google-api-go-generator/gen.go    Sun Jul 08 23:44:39 2012 +0100
@@ -1043,6 +1043,11 @@
        pn("if err := googleapi.CheckResponse(res); err != nil { return %serr }", nilRet)
        if retTypeComma == "" {
                pn("return nil")
+       } else if a.needsDataWrapper() {
+               s := responseType(meth.m)[1:]
+               pn("ret := &struct{ Data *%s `json:data,omitempty`}{Data: 
new(%s)}", s, s)
+               pn("if err := json.NewDecoder(res.Body).Decode(ret); err != nil 
{ return nil, err }")
+               pn("return ret.Data, nil")
        } else {
                pn("ret := new(%s)", responseType(meth.m)[1:])
                pn("if err := json.NewDecoder(res.Body).Decode(ret); err != nil { return nil, err }")

do something with enums

[email protected] on 25 Aug 2011 at 9:10:

The JSON has enums described, showing possible values.

Should probably promote to documentation at least, if not generate types or 
run-time checks on setters.

bigquery JobsInsertCall.Do() should always use application/octet-stream for media

gavaletz on 2 May 2013 at 2:36:

What steps will reproduce the problem?
1. Create bigquery.Service
2. Add Job to load data to BigQuery with CSV data provided as POST
3. add Media
4. call Do

What is the expected output? What do you see instead?
Media (CSV data) should be added with "Content-Type: application/octet-stream"

If it is compressed it gets added with application/gzip and if the CSV data is 
not compressed (as created by http://golang.org/pkg/encoding/csv/) it is 
identified as text/plain.

What version of the product are you using? On what operating system?
Go working from tip
google-api-go-client working from tip
Linux x86_64

Please provide any additional information below.
According to the documentation provided for BigQuery the data section of the 
load job should always have the content type application/octet-stream.  You can 
work around this by creating a custom io.Reader that satisfies the type 
googleapi.ContentTyper interface, but that is not obvious and there is no case 
where this function should use anything other than content type 
application/octet-stream.

func (c *JobsInsertCall) Do() (*Job, error) {
         ...
        contentLength_, hasMedia_ := googleapi.ConditionallyIncludeMedia(c.media_, &body, &ctype)
         ...
}

This is just another pitfall for anyone brave/dumb enough to try to use Go with 
BigQuery - myself included.

Socket leak caused by not closing res.Body

nickcw on 18 Jan 2013 at 9:03:

The drive/v2 API is leaking sockets and go routines (that is the API I've been 
playing with, the problem may be more widespread) by not closing its http 
response bodies.

As an example this patch fixes the problem for the Files.List call.  As far as 
I can see all the drive API calls have the same problem.

diff -r 7bfdc57efcf2 drive/v2/drive-gen.go
--- a/drive/v2/drive-gen.go Wed Dec 12 15:06:54 2012 -0800
+++ b/drive/v2/drive-gen.go Fri Jan 18 20:57:25 2013 +0000
@@ -2903,6 +2903,7 @@
    if err != nil {
        return nil, err
    }
+   defer res.Body.Close()
    if err := googleapi.CheckResponse(res); err != nil {
        return nil, err
    }

www.blogger.com

thewilianto on 21 Dec 2012 at 8:44:

What steps will reproduce the problem?
1. G+ on our blog [http://thewilys333.blogspot.com] not connected / not working 
with our Google+ account.
2. Sharpen our blog so widespread and easily searchable.
3.

What is the expected output? What do you see instead?
We wish her ​​out well and easy to obtain.

What version of the product are you using? On what operating system?
We use blogger.com, common version.

Please provide any additional information below.
We hope to help her problem and its development, thanks.

setting a report's startDate and endDate in the dfareporting api to json null

ffdavidson on 16 Oct 2013 at 8:58:

What steps will reproduce the problem?
1. In the Report Builder UI create a report with a startDate and endDate
2. Attempt to patch the report to a relativeDateRange
3. Try to set the startDate and endDate to ""
3. An Error 400 is produced

What is the expected output? What do you see instead?
There needs to be a method of setting the startDate and endDate to the JSON 
null (which is null and not "null" in the current JSON output, see below)

What version of the product are you using? On what operating system?
dfareporting v1.3

Please provide any additional information below.
Hey Frank,

Ah, very interesting. In order for that to work, the expected JSON value is 
null - not the string "null". Consider the following request:


PATCH 
https://www.googleapis.com/dfareporting/v1.3/userprofiles/857012/reports/1680785


Content-Type: application/json


{
  "criteria": {
    "dateRange": {
      "kind": "dfareporting#dateRange",
      "startDate": null,
      "endDate": null,
      "relativeDateRange": "LAST_7_DAYS"
    }
  }
}

This will do what you want to do. I'm not sure if this is possible using the Go 
library; if its not, I'd recommend filing it as a bug on their issue tracker.


Regards,
- Joseph DiLallo, the DFA API Team

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.