🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.delphi
Article #345828

Re: Youtube Api

#345828
From: m
Date: Wed, 07 Jun 2017 21:24
84 lines
3197 bytes
W dniu 2017-06-07 o 16:07, Roman Tyczka pisze:
> On Wed, 7 Jun 2017 15:26:07 +0200, mmm wrote:
> 
>> Sa zaimplementowane jakieś klasy dla API Delphi ?
>> Czy trzeba to wszystko zrobić ręcznie za pomocą TRESTClient ?
>>
>> Poproszę o podpowiedz jak korzystać z API Googla w aplikacji delphi
> 
> Za darmo - rzeźba za pomocą RESTa jak piszesz.

Struganie ręczne to mniej wiecej tak jak poniżej 
(jObject.Get('kind').JSONValue.Value )  czy tez można zrobic to jakoś 
lepiej ? Jak taki obiekt w Json przenieść do klasy dziedziczącej po 
TObject ewentualnie na podstawie RTTI jakies automatyczne przenoszenie 
danych ?


uses REST.Client, System.JSON

procedure TForm4.Button2Click(Sender: TObject);
var
   RESTClient: TRESTClient;
   RESTRequest: TRESTRequest;
   RESTResponse: TRESTResponse;
var
   jAll: TJSONValue;
   jItems:TJSonValue;
   jObject: TJSonObject;
begin
   RESTResponse := TRESTResponse.Create(self);;
   RESTClient := TRESTClient.Create(self);
   RESTRequest := TRESTRequest.Create(self);

   try

     RESTClient.BaseURL := 
'https://www.googleapis.com/youtube/v3/playlistItems';
     with RESTClient.Params.AddItem() do
     begin
       name := 'part';
       Value := 'contentDetails,id';
     end;
     with RESTClient.Params.AddItem() do
     begin
       name := 'maxResults';
       Value := '50';
     end;
     with RESTClient.Params.AddItem() do
     begin
       name := 'playlistId';
       Value := 'PLBCF2DAC6FFB574DE';
     end;
     with RESTClient.Params.AddItem() do
     begin
       name := 'key';
       Value := 'AIzaSyCgB1DcSAG7_bSbKn9z_9Y7HM6jhefN-eQ';
     end;

     RESTRequest.Client := RESTClient;
     RESTRequest.Response := RESTResponse;

     RESTResponse.RootElement := 'items';
     RESTRequest.Execute;


     if RESTResponse.StatusCode = 200 then
     begin
       showmessage(RESTResponse.Content);
       jAll := RESTResponse.JSONValue;
       if (jAll is TJSONArray) then
       begin
         jObject := (jAll as TJSONArray).Items[0] as TJSonObject;
         showmessage(jObject.Get('kind').JSONValue.Value);
       end;
     end;


   finally
     RESTResponse.Free;
     RESTClient.Free;
     RESTRequest.Free;
   end;

end;
Technical Details
Message-ID: <oh9qur$t4o$1@portraits.wsisiz.edu.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!wsisiz.edu.pl!.POSTED.host-81-190-138-129.dynamic.mm.pl!not-for-mail
References: <oh8uth$904$1@portraits.wsisiz.edu.pl> <2ppfkf8fdlus$.dlg@tyczka.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!wsisiz.edu.pl!.POSTED.host-81-190-138-129.dynamic.mm.pl!not-for-mail
From: m <mmmm@mmmmm.pl>
Newsgroups: pl.comp.lang.delphi
Subject: Re: Youtube Api
Date: Wed, 7 Jun 2017 23:24:25 +0200
Organization: http://www.wit.edu.pl
Message-ID: <oh9qur$t4o$1@portraits.wsisiz.edu.pl>
References: <oh8uth$904$1@portraits.wsisiz.edu.pl> <2ppfkf8fdlus$.dlg@tyczka.com>
Mime-Version: 1.0
Injection-Date: Wed, 7 Jun 2017 21:24:43 -0000 (UTC)
Injection-Info: portraits.wsisiz.edu.pl; posting-host="host-81-190-138-129.dynamic.mm.pl:81.190.138.129"; logging-data="29848"; mail-complaints-to="abuse@wsisiz.edu.pl"
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1
In-Reply-To: <2ppfkf8fdlus$.dlg@tyczka.com>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit