Recent

Author Topic: Example for youtube api using developer key?  (Read 2275 times)

mr-highball

  • Full Member
  • ***
  • Posts: 231
    • Highball Github
Example for youtube api using developer key?
« on: August 13, 2021, 01:46:21 am »
Hey, I was trying to put together a small app to index youtube videos using the YouTube search resource from the Google api package. I looked at the calendar example but it requires consent from a user, and I want to use a developer key instead.

I see the dev key property in the handler... but when I run the code it still complains about "not authenticated"
https://github.com/mr-highball/yt-indexer/blob/40a3cbe425c6482759ea8c6257ac6808d9bb71ce/src/yt.indexer.pas#L127

I've been paroozing the source but I figure it wouldn't hurt to ask if someone has an example out there

Leledumbo

  • Hero Member
  • *****
  • Posts: 8386
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Example for youtube api using developer key?
« Reply #1 on: August 14, 2021, 11:16:50 pm »
I don't see any where AuthMethod property is read, so my guess is that you'll always use OAuth2 for authentication, it's quite clear reading googleclient source code. If you only need to call unauthenticated APIs such as channels.list, I suggest using fphttpclient instead as it's way simpler like so:
Code: Pascal  [Select][+][-]
  1. uses fphttpclient,fpjson,jsonparser;
  2. ...
  3. JSON := TJSONObject(GetJSON(TFPHTTPClient.SimpleGet('https://www.googleapis.com/youtube/v3/channels?forUsername=<channel username here>&key=<your api key here>')));
  4. (*
  5.  
  6. will return something like:
  7. {
  8.   "kind": "youtube#channelListResponse",
  9.   "etag": "EoDlEPBUv4rVlFusZFe1fTBsGRI",
  10.   "pageInfo": {
  11.     "totalResults": 1,
  12.     "resultsPerPage": 5
  13.   },
  14.   "items": [
  15.     {
  16.       "kind": "youtube#channel",
  17.       "etag": "jmginRTMBuf36NMFkYvfDyOTTHM",
  18.       "id": "UCc_8N8sPB8RWKRfPxWjlFCg"
  19.     }
  20.   ]
  21. }
  22.  
  23.  
  24. *)
  25.  

mr-highball

  • Full Member
  • ***
  • Posts: 231
    • Highball Github
Re: Example for youtube api using developer key?
« Reply #2 on: August 14, 2021, 11:44:20 pm »
Thanks for the reply. I ended up doing that and was still able to use the search list result object (with the library) to parse the json

 

TinyPortal © 2005-2018