https://github.com/kazhuravlev/go-unsplash
Go client for unsplash.com API
https://github.com/kazhuravlev/go-unsplash
go mit-license unsplash-api
Last synced: about 1 year ago
JSON representation
Go client for unsplash.com API
- Host: GitHub
- URL: https://github.com/kazhuravlev/go-unsplash
- Owner: kazhuravlev
- License: mit
- Created: 2018-12-09T00:01:27.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-12-09T23:41:13.000Z (over 7 years ago)
- Last Synced: 2025-04-01T16:16:18.373Z (about 1 year ago)
- Topics: go, mit-license, unsplash-api
- Language: Go
- Homepage:
- Size: 33.2 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Go client for unsplash.com API
## Installation
```bash
go get github.com/kazhuravlev/go-unsplash
```
## Run tests
To run tests you must [register application](https://unsplash.com/oauth/applications/new).
After register application copy `Access Key` and `Secret Key` and then:
```bash
go run tools/main.go -accessKey= -secretKey=
```
Go to URL and authorize application to required permissions. After accept
request you get `Authorization code` string. Copy it and:
```bash
go run tools/main.go -accessKey= -secretKey= -code=
```
You must see `Access Token` in terminal output. Copy it.
To run all tests with given credentials just type:
```bash
export TEST_ACCESS_KEY=; TEST_SECRET_KEY=; TEST_ACCESS_TOKEN= go test -v ./...
```
## Usage
```go
package main
import (
"context"
"fmt"
"github.com/kazhuravlev/go-unsplash/unsplash"
"golang.org/x/oauth2"
"log"
)
func main() {
accessToken := ""
source := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: accessToken, TokenType: "Client-ID"},
)
httpClient := oauth2.NewClient(context.Background(), source)
client, err := unsplash.New(unsplash.WithHttpClient(httpClient))
if err != nil {
log.Fatal(err)
}
photos, err := client.GetRandomPhotos(context.Background(), unsplash.GetRandomPhotosOptions{})
if err != nil {
log.Fatal(err)
}
fmt.Println(photos[0].Urls.Full)
}
```