Create an App Displaying My Youtube Videos | C2C Community
Solved

Create an App Displaying My Youtube Videos

  • 2 October 2022
  • 2 replies
  • 24 views

Userlevel 1

Hello. First time asking a question in the community. I would like to create a native android app displaying videos from my YouTube channel. I am having a difficult time figuring out how to get the access token.

Here is what I have figured out so far.

1. I know which APIs to call.
https://developers.google.com/youtube/v3/docs/channels/list
https://developers.google.com/youtube/v3/docs/playlistItems/list

2. I created curls for these APIs

GetYouTubeChannelsList

curl --location -g --request GET 'https://youtube.googleapis.com/youtube/v3/channels?part=contentDetails&forUsername={YOUR_USER_NAME}&key={YOUR_API_KEY}' \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json'

GetYouTubePlaylistItems

curl --location -g --request GET 'https://youtube.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId={YOUR_PLAYLIST_ID}&key={YOUR_API_KEY}' \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json'

Due to not knowing where I can receive the access token, I am stuck.

3. I found a google api client library that seems to allow authentication behind the scenes, where you can receive an access token by only providing your api key which you generate on Google Cloud console. However, the class is deprecated.

implementation 'com.google.api-client:google-api-client:1.34.0'

The `GoogleCredential` class is deprecated.

4. After further research, I found another auth library. I thought that maybe this was a replacement for GoogleCrediential. However, I do not understand how to use it. What steps do I need to do exactly for GoogleCredentials.getApplicationDefault() to work?

implementation 'com.google.auth:google-auth-library-oauth2-http:0.17.1'


Unfortunately, there isn’t too many code examples online. 

My ASKs
(1) I would like to add an access token to my curl script and get a successful response.
(2) I would like to know which libraries should be used for the type of application I want to build.

icon

Best answer by ilias 3 October 2022, 08:33

View original

2 replies

Userlevel 7
Badge +58

Hi @drxeno02,

are you using Firebase, Firestore for your Android app or not?

Is it a Kotlin, Java, Flutter app?

Have you checked the two links below?

How to Get a YouTube API Key

OAuth 2.0 for Mobile & Desktop Apps

 

The more you tell us, the better for our members.

Userlevel 1

Hello.

I am using Kotlin. And no, I am making API calls outside of Firebase and other Google services. I was using POSTMAN to play around with the APIs.

How to Get a YouTube API Key
I have reviewed this documentation. See this part of the article » 4. Try it out using Google’s API explorer tool. That is how I got my curl. The curl doesn’t work without an access token. This is my question, where do you get that access token. Somewhere there has to be an authentication endpoint or a /getToken endpoint. That is really where I am confused.

OAuth 2.0 for Mobile & Desktop Apps
Regarding this, I may have missed this documentation. Looks like I should try and use this curl.

curl \
--request POST \
--data "code=[Authentcation code from authorization link]&client_id=[Application Client Id]&client_secret=[Application Client Secret]&redirect_uri=urn:ietf:wg:oauth:2.0:oob&grant_type=authorization_code" \
https://accounts.google.com/o/oauth2/token

I will try it. This looks like what I am looking for. Thank you!

Other references I found (for anyone else with the same issue): https://gist.github.com/LindaLawton/cff75182aac5fa42930a09f58b63a309

Reply