Używam Embarcadero Delphi 10.4.2 i Windowsa 10. Dodałem aplikację w trybie device do REST Api na koncie Allegro Sandbox. Mam kod do autoryzacji do Allegro REST Api Sandbox:
procedure TForm1.FormCreate(Sender: TObject);
var
sEndodedAuth: string;
begin
with TBase64Encoding.Create(0) do
begin
sEndodedAuth:= Encode(CLIENT_ID + ':' + CLIENT_SECRET);
Free;
end;
Restrequest1.Client:= RestClient1;
RestClient1.BaseURL:= 'https://allegro.pl.allegrosandbox.pl';
RestRequest1.Method:= TRESTRequestMethod.rmPOST;
RestRequest1.Resource:= 'auth/oauth/device';
RestRequest1.AddParameter('Authorization', 'Basic ' + sEndodedAuth,
TRESTRequestParameterKind.pkHTTPHEADER, [TRESTRequestParameterOption.poDoNotEncode]);
RestRequest1.AddParameter('Content-Type','application/x-www-form-urlencoded',
TRESTRequestParameterKind.pkHTTPHEADER, [TRESTRequestParameterOption.poDoNotEncode]);
RestRequest1.AddParameter('client_id', CLIENT_ID, TRESTRequestParameterKind.pkGETorPOST);
RestClient1.ContentType:='application/x-www-form-urlencoded';
RestRequest1.Execute;
result.Text:= RestResponse1.Content;
end;
Po wykonaniu powyższego kodu w polu tekstowym mam odpowiedź:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:th="http://www.thymeleaf.org">
<head>
<title>Allegro.pl - nie możemy wyświetlić strony</title>
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"/>
<meta name="robots" content="noindex, nofollow"/>
<link href="//cdn.allegrostatic.com/login/dist/css/main-4663f05c.css" rel="stylesheet"/>
</head>
<body class="_kucdo" data-layout="metrum">
{"medallia.users-with-smart":{"sessionStorageValue":"0","sessionStorageKey":"userWithSmart"},"allegro.multisearch.modal":{"hashMatchStrategy":"exact","maxWidth":"fluid","closeOption":"HIDE_MOBILE_BOTTOM_BUTTON","disableAnimation":true,"showInitially":false,"triggerLinkHash":"multisearch","size":"extraSmall","simulateModalAsPage":true,"isContentPaddingDisabled":true,"triggerLinkStyle":"link"},"allegro.multisearch.spinner":{},"allegro.metrumHeader":{"brandUrl":"https://allegro.pl.allegrosandbox.pl","subscribedNotificationBadges":["reviews","coins"],"secondaryBarEnabled":true,"subBrandText":"","userMenuEnabled":true,"userName":"","metrumMaxWidthEnabled":false,"mobileModeEnabled":false,"esiEnabled":true,"pageCachedEnabled":false,"messagesEnabled":false,"stickyModeEnabled":true},"allegro.metrumHeader.search":{"enableMultisearch":true,"inputPlaceholder":"czego szukasz?","enableSuggesterHistory":true,"enableSearchScopeUsers":true,"microdataConfig":{"enable":false,"origin":"https://allegro.pl"},"staticQueryParameters":[],"enableCustomPerformanceMarks":false,"inputPhrase":"","enableClearButton":false,"enableFullscreen":false,"departmentsFilter":{"children":[{"code":"household","name":"Dom i ogród","alias":"dom-i-ogrod","id":"5","leaf":false,"url":"/dom-i-ogrod"},{"code":"baby","name":"Dziecko","alias":"dziecko","id":"11763","leaf":false,"url":"/dziecko"},{"code":"electronics","name":"Elektronika","alias":"elektronika","id":"42540aec-367a-4e5e-b411-17c09b08e41f","leaf":false,"url":"/elektronika"},{"code":"company","name":"Firma i usługi","alias":"firma","id":"4bd97d96-f0ff-46cb-a52c-2992bd972bb1","leaf":false,"url":"/firma"},{"code":"collections.art","name":"Kolekcje i sztuka","alias":"kolekcje-i-sztuka","id":"a408e75a-cede-4587-8526-54e9be600d9f","leaf":false,"url":"/kolekcje-i-sztuka"},{"code":"culture.entertainment","name":"Kultura i rozrywka","alias":"kultura-i-rozrywka","id":"38d588fd-7e9c-4c42-a4ae-6831775eca45","leaf":false,"url":"/kultura-i-rozrywka"},{"code":"fashion.beauty","name":"Moda","alias":"moda","id":"ea5b98dd-4b6f-4bd0-8c80-22c2629132d0","leaf":false,"url":"/moda"},{"code":"automotive","name":"Motoryzacja","alias":"motoryzacja","id":"3","leaf":false,"url":"/motoryzacja"},{"code":"real.estate","name":"Nieruchomości","alias":"nieruchomosci","id":"20782","leaf":false,"url":"/nieruchomosci"},{"code":"sports.leisure","name":"Sport i turystyka","alias":"sport-i-turystyka","id":"3919","leaf":false,"url":"/sport-i-turystyka"},{"code":"supermarket","name":"Supermarket","alias":"supermarket","id":"258832","url":"/supermarket"},{"code":"beauty","name":"Uroda","alias":"uroda","id":"1429","leaf":false,"url":"/uroda"},{"code":"health","name":"Zdrowie","alias":"zdrowie","id":"121882","leaf":false,"url":"/zdrowie"}],"parentId":""},"enableRewriteSuggestionButton":false,"advancedSearchCriterias":[{"checked":false,"id":"searchInDescriptionChange","label":"szukaj też w opisach ofert","queryParameter":{"value":"1","key":"description"}}],"multisearchModalHashTrigger":"#multisearch","enableSuggestionsForEmptyPhrase":false,"enableInputAutofocus":false,"enableSearchScopeEnded":true,"enableSearchScopeCharity":true,"enableSuggestionRemovalButtonOnHover":true},"allegro.performance.mark":{"performanceMarkType":"FirstContentfulPaint"},"allegro.watched.offers.status":{"layout":"inHeader"},"allegro.user.inbox":{},"allegro.metrumHeader.cart":{"domainName":"allegro.pl.allegrosandbox.pl","isWithinToolbar":false,"isAuthenticated":false,"previewEnabled":true},"allegro.messageCenter.header":{"isAuthenticated":false,"messageCenterBasePath":"/moje-allegro/moje-konto/centrum-wiadomosci/wiadomosci","messageCenterSurveyLink":"https://ankieta.allegro.pl/index.php/665263?lang=pl","displayMessageCenterSurvey":false},"allegro.login.smart.status":{"isPageCached":false,"smartMAPageUrl":"/moje-allegro/zakupy/allegro-smart","smartLandingPageUrl":"/smart","view":"compact"},"allegro.user.menu":{"activeTab":"shoppingTab","requestUrl":{"path":"/headerService/header","query":null},"isAnonymised":false,"isAuthenticated":false,"mobileModeEnabled":false},"allegro.richText.image":{"content":"<span style=\"display: block; max-width: 300px; margin: 0 auto;\"><img style=\"width: 100%;\" class=\"lazyload\" src=\"https://assets.allegrostatic.com/metrum/placeholder/placeholder-20d85ed501.svg\" data-src=\"https://a.allegroimg.com/original/122180/20799df0408198ded7d97a1c0167\" height=\"183\"></span>","disableBottomMargin":false},"allegro.richText":{"disableBottomMargin":false,"content":"<h3 style=\"text-align: center;\">Witaj w allegro!</h3>\n<p style=\"text-align: center;\"><small>Zaloguj się i zobacz swoje zakupy, obserwowane oferty i powiadomienia. W Allegro jesteś u siebie!</small></p>"},"layout.container":{"marginBottom":0,"separatorTop":false,"fullHeight":false,"titleAboveCard":false,"marginTop":0,"fullHeightL":false,"hasBorder":false,"inverseColor":false,"headerCenter":false,"fullHeightS":false,"titleHx":"2","card":false,"fullHeightM":false,"isMarginTopForTitleAboveCardDisabled":false,"headerSize":"0","fullHeightX":false,"maxWidth":"full-width"},"allegro.gdpr.consents.sheet":{"isInternal":false,"cookieConfiguration":{},"layout":"SHEET","isRwd":false,"pageCached":false,"initialView":"HOME"},"meta":{"canonicalUrl":null,"alternates":[],"canonicalOrigin":"https://allegro.pl.allegrosandbox.pl","enableDeprecatedBrowserPlugin":true,"skin":"esi","gtmId":"GTM-FXVJ","isUsabillaEnabled":false,"sentryConfiguration":{"enabled":true,"sampleRate":0.1},"botDetectorConfiguration":{"collectorURL":"https://js-data.allegro.pl/js/","enabled":true},"noindexCondition":true,"facebookTrackingConfiguration":{"hostUrl":"https://www.facebook.com","pixelId":"1741891762558019","shouldSendPageView":true},"isEsi":true,"enableChatPlugin":true,"metrumBundlerEnabled":false,"nofollowCondition":true,"isEngagementMeasuringEnabled":false,"performancePinterConfiguration":{"cmuid":"","enabled":true,"samplingRate":1},"gemiusEnabled":true,"cartConfiguration":{"precartLayerUrl":"/koszyk/warstwa"},"cacheTimeInSeconds":0}}
<div class="_3d7xx">
<div class="_1yyhi">
<div class="_3kk7b _3kk7b--hidden _3kk7b--hidden@sm _1755t">
<div class="_dotn1"><img class="error-tv" src="//cdn.allegrostatic.com/login/dist/images/error_tv-bb1d70b8.svg" alt="error" width="500" height="500" /></div>
</div>
<div class="_3kk7b _vnd3k _1755t">
<div class="_1yyhi">
<div class="_3kk7b _vnd3k">
<div class="error-msg">
<div>
<h1 class="_z853a _mbz3k error-title">Nie możemy wyświetlić strony</h1>
<p class="_1akfs _12ycd _a09nn"></p>
<p class="_1akfs _12ycd _a09nn"><span>Numer błędu:</span> <b>f4083ae4c5b53cd4</b></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{"allegro.footer.lite.pl":{"logoUrl":"https://assets.allegrostatic.com/opbox/allegro.pl/playground/Metrum%20Footer%20BETA/allegro-1.svg","termsMessage":"Korzystanie z serwisu oznacza akceptację ","termsUrl":"/regulamin","termsName":"regulaminu"},"meta":{"canonicalUrl":null,"alternates":[],"canonicalOrigin":"https://allegro.pl.allegrosandbox.pl","cartConfiguration":{"precartLayerUrl":"/koszyk/warstwa"},"enableDeprecatedBrowserPlugin":true,"performancePinterConfiguration":{"cmuid":"","enabled":true,"samplingRate":1},"isUsabillaEnabled":false,"facebookTrackingConfiguration":{"hostUrl":"https://www.facebook.com","pixelId":"1741891762558019","shouldSendPageView":true},"sentryConfiguration":{"enabled":true,"sampleRate":0.1},"enableChatPlugin":true,"isEsi":true,"metrumBundlerEnabled":false,"nofollowCondition":true,"botDetectorConfiguration":{"collectorURL":"https://js-data.allegro.pl/js/","enabled":true},"isEngagementMeasuringEnabled":false,"gtmId":"GTM-FXVJ","skin":"","noindexCondition":true,"gemiusEnabled":true,"cacheTimeInSeconds":15}}
</body>
</html>
Czy to jest poprawna odpowiedź po autoryzacji ? Jak wykonać poprawnie autoryzację i jak pobrać id kategorii Allegro do tablicy za pomocą kodu Delphi ?