How do I use Google's “Simple API Access key” to access Google Calendar info (PHP)?

后端 未结 5 1336
温柔的废话
温柔的废话 2020-12-18 20:04

I\'m trying to use the Google API v3 to access one google calendar and according to the documentation here : http://code.google.com/apis/calendar/v3/using.html#intro and her

5条回答
  •  一整个雨季
    2020-12-18 20:13

    I got to this thread when trying to do the same today. Although this is way late, but the answer is YES, there is actually simple API key for those apis that does not need user authorizations, and the official client library support this.

    The api library do this by Options, which is key, value pair.

    Take the example of get information of a given youtube video, you would use this api: https://godoc.org/google.golang.org/api/youtube/v3#VideosListCall.Do

    To use api key, simply make a type that implements the CallOption interface, and let it return the api key:

    type APIKey struct {
    }
    
    func (k *APIKey) Get() (string, string) {
        return "key", "YOU API KEY HERE"
    }
    

    Then when calling the API, supply the APIKey to it:

    youtube, err := youtube.New(&http.Client{})
    call := youtube.Videos.List("snippet,contentDetails,statistics").Id(id)
    rsp, err := call.Do(opt)
    

    This way, you can construct the youtube client with the vallina http client, rather than oauth client, and enjoy the simple api key.

    The first answer said you can use http GET directly, but then you will need to handle the errors and parse the result yourself.

提交回复
热议问题