Question

I see that yahoo yql can get many information in web services which can be very useful. However, when I search for "Delphi yql" in google. There are no useful information returned. Are there any help and samples of how to use Delphi to send request and get result from yql? Thanks a lot.

Était-ce utile?

La solution

YQL is an HTTP-based protocol. There are plenty of examples of using HTTP in Delphi. Here is one using Indy's TIdHTTP component to send Yahoo's example YQL query:

var
  YqlQuery: string;
  YqlResult: string;
  YqlResultCharset: string;
  YqlResultFormat: string;
  Url: string;
begin    
  YqlQuery := 'select * from geo.places where text="sunnyvale, ca"';
  YqlResultCharset := 'iso-8859-1'; // any valid IANA charset. YQL defaults to UTF-8
  YqlResultFormat := 'xml'; // can be either xml or json

  IdHTTP1.Request.ContentType := 'text/html';
  IdHTTP1.Request.Charset := YqlResultCharset;
  Url := 'http://query.yahooapis.com/v1/public/yql?q=' + TIdURI.ParamsEncode(YqlQuery) + '&format=' + YqlResultFormat;

  {
  Alternatively:

  IdHTTP1.Request.ContentType := '';
  IdHTTP1.Request.Charset := '';
  Url := 'http://query.yahooapis.com/v1/public/yql?q=' + TIdURI.ParamsEncode(YqlQuery + ' and charset="' + YqlResultCharset + '"') + '&format=' + YqlResultFormat;
  }

  YqlResult := IdHTTP1.Get(Url);
  // parse YqlResult as needed...
end;

Refer the Yahoo's documentation for more details.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top