# Youtube Channel names

The information about design of this flow can be found here: [Tech Design for YouTube Bulk Reports ETL](https://docs.google.com/document/d/1jKJ57u1ywZu2Cjo1zh2Mbs0WSHnF-wyM_i11hxI88eQ/edit#heading=h.3cxfogq8xpsi)

### Credentials 

Flow looks for Google API credentials in `feed_ingestion/conf/youtube_access_token.json`. The token is downloaded from `s3://systems-cloudformation/ows-configs/youtube_channel_names_credentials/youtube_access_token.json` during build process.

Example:
```json
{
  "access_token": "<ACCESS_TOKEN>",
  "client_id": "<CLIENT_ID>",
  "client_secret": "<CLIENT_SECRET>",
  "refresh_token": "<REFRESH_TOKEN>",
  "token_expiry": "2021-08-13T19:00:37Z",
  "token_uri": "https://oauth2.googleapis.com/token",
  "user_agent": "channel-names",
  "revoke_uri": "https://accounts.google.com/o/oauth2/revoke",
  "id_token": null,
  "token_response": {
    "access_token": "<ACCESS_TOKEN>",
    "scope": "https://www.googleapis.com/auth/youtubepartner-channel-audit",
    "token_type": "Bearer",
    "expires_in": 3599,
    "refresh_token": "<REFRESH_TOKEN>",
  },
  "scopes": [
    "https://www.googleapis.com/auth/youtubepartner-channel-audit"
  ],
  "token_info_uri": "https://www.googleapis.com/oauth2/v3/tokeninfo",
  "invalid": false,
  "_class": "OAuth2Credentials",
  "_module": "oauth2client.client"
}
```

Please note: `user_agent` in the example above, that's the credential set name.
Please note: `scope` and `scopes` in the example above, this must be the same as in this example or the flow won't be able to access the channels API. For complete reference please read [google developer's guide](https://developers.google.com/youtube/v3/docs/channels/list).

To user token generator you need to set these environment variables:
GOOGLE_API_SECRETS_FILE_PATH=<secrets-file-downloaded-from-gcp-api-console>
GOOGLE_API_TOKEN_FILE_PATH=<path-to-existing-token>
GOOGLE_API_APPLICATION_NAME='datalytics-etls'

To generate them use [generate_google_api_token.py](../../bin/generate_google_api_token.py) script

## Manual token generation

1. Go to ***API & Services*** -> [Credentilas](https://console.cloud.google.com/apis/credentials) 
2. Copy **client Id** and **client Secret** from credential set named `channel-names`
3. To create **accessToken** and **refreshToken** go to *[OAuth 2.0 Playground](https://developers.google.com/oauthplayground/)*
4. choose `Use your own OAuth credentials` in `OAuth 2.0 configuration` (gears in the top right corner)
5. paste **client Id** and **client Secret** to the config fields
6. select scope named `https://www.googleapis.com/auth/youtubepartner-channel-audit`
7. click `Authorize API` button 
8. click the `Exchange authorization code for tokens` button
9. copy JSON refresh and an access token which will appear on the right side
10. paste the credentials (`client_id`, `client_secret`, `access_token`, `refresh_token`) to the placeholders of the example from the previous section
