Skip to content
This repository was archived by the owner on Aug 12, 2025. It is now read-only.

Commit 4ed9733

Browse files
Explain how to authorize requests and run samples
Fix explanation of how to authorize requests and run samples.
1 parent c8a19d2 commit 4ed9733

1 file changed

Lines changed: 23 additions & 15 deletions

File tree

go/README.md

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,37 @@ To run these code samples, you will need to install the dependent libraries via
44
the "go get" command. See the client library's getting started guide for more detail:
55
https://github.com/google/google-api-go-client/blob/master/GettingStarted.md
66

7-
The keyword search and topic search samples can be run via the standard "go run" command
8-
once the developerKey constant is populated with an API key created at
9-
https://developers.google.com/console.
7+
You also need to enable the YouTube Data API for the project associated with your developer
8+
credentials.
109

11-
Example usage:
10+
## Authorization credentials
11+
To run any sample that does not require user authorization, such as search\_by\_keyword.go,
12+
you need to replace the value of the `developerKey` constant with a valid API key:
1213

13-
  go run search\_by\_keyword.go
14+
```
15+
const developerKey = "YOUR DEVELOPER KEY"
16+
```
1417

15-
The YouTube Data API must be enabled for the project associated with this key.
16-
17-
To run any sample that requires authorization on behalf of a user, such as checking
18-
for uploads, this requires the shared oauth2.go file to be passed as a parameter to "go run".
19-
These samples require an OAuth 2.0 client ID and client secret pair, which can
20-
also be created at the Google API console at https://developers.google.com/console. After
18+
To run any sample that requires authorization on behalf of a user, such as retrieving the
19+
authenticated user's uploads, you need an OAuth 2.0 client ID and client secret pair. These
20+
can be created at the Google API console at https://developers.google.com/console. After
2121
creating your OAuth 2.0 credentials, download the client\_secret.json file to the directory
2222
in which you are running these samples.
2323

24-
Example usage:
24+
## Running samples
25+
26+
Samples can be run with the standard "go run" command as long as your API key or OAuth 2.0
27+
credentials are in place. The samples use the `errors.go` file to
28+
print out API errors, so you need to also include that file in the "go run" command. Samples
29+
that require authorization also require the `oauth2.go` file to be included in the
30+
"go run" command:
2531

26-
go run my\_uploads.go oauth2.go
32+
Example usages:
2733

28-
The **oauth2.go** file contains code that is shared between the code samples that require
29-
OAuth 2.0 authorization, so it must be passed as a parameter to "go run".
34+
```
35+
  go run search\_by\_keyword.go errors.go
36+
go run my\_uploads.go errors.go oauth2.go
37+
```
3038

3139
More information about the YouTube APIs can be found at https://developers.google.com/youtube.
3240

0 commit comments

Comments
 (0)