Autoryzacja w allegro i pobieranie id kategorii do tablicy

0

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 ?

0

Tak na oko - nigdy nie używałem ani nie będę używał HTTP z borlandów - to wywołujesz to w sposób bardzo daleki od REST-a, jakieś url encoded itd...

Pachnie jak wklejka z innego kodu.

PS. Puść ten zwrócony HTML przez formatowanie, żeby dało się czytać

0

Sformatowana odpowiedź w htmlu:

<!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>

0

Poprawiłem wartość zmiennej CLIENT_ID i CLIENT_SECRET i teraz wydaje mi się że poprawnie jest wykonywana autoryzacja bo w odpowiedzi mam:

{"device_code":"*******************************","expires_in":3600,"user_code":"******************","interval":5,"verification_uri":"https://allegro.pl.allegrosandbox.pl/uzytkownik/bezpieczenstwo/skojarz-aplikacje","verification_uri_complete":"https://allegro.pl.allegrosandbox.pl/uzytkownik/bezpieczenstwo/skojarz-aplikacje?code=*********************"}

Teraz jest pytanie jak pobrać id kategorii do tablicy ?

Jednak wydaje mi się że w odpowiedzi brakuje access_token bo jest device_code i user_code a nie ma access_token. O acces_token jest napisane pod linkiem https://developer.allegro.pl/getting_started/. I teraz nie wiem czy konieczny jest ten acces_token do requestów REST API czy wystarczy ten device_code i user_code bo dodałem linijkę kodu:

RESTRequest1.AddParameter('grant_type', 'client_credentials', TRESTRequestParameterKind.pkGETorPOST);

i okazało się że odpowiedź jest taka sama więc jeśli ten access_token jest potrzebny to co zrobić żeby go uzyskać ?

0

Już doszedłem jak uzyskać access_token. Wszystko jest napisane pod linkiem https://developer.allegro.pl/auth/#device-flow

0
AnyKtokolwiek napisał(a):

Tak na oko - nigdy nie używałem ani nie będę używał HTTP z borlandów - to wywołujesz to w sposób bardzo daleki od REST-a, jakieś url encoded itd...

Że application/x-www-form-urlencoded nie jest RESTowe? :D Oj, ale byś się zdziwił.

0

Wykonałem kod żeby pobrać z allegro kategorie główne:

procedure TForm1.FormCreate(Sender: TObject);
begin
Restrequest1.Client:= RestClient1;
RestClient1.BaseURL:= 'https://api.allegro.pl.allegrosandbox.pl';
RestRequest1.Method:= TRESTRequestMethod.rmPOST;
RestRequest1.Resource := 'sales/categories';
RestRequest1.AddParameter('Authorization', 'Basic: Bearer ' +  access_token,
    TRESTRequestParameterKind.pkHTTPHEADER, [TRESTRequestParameterOption.poDoNotEncode]);
    RestRequest1.AddParameter('Accept', 'application/vnd.allegro.public.v1+json',
    TRESTRequestParameterKind.pkHTTPHEADER, [TRESTRequestParameterOption.poDoNotEncode]);
RestClient1.ContentType:='application/vnd.allegro.public.v1+json';
RestRequest1.Execute;
result.text = RestResponse1.Content;
end;

i w odpowiedzi otrzymuje status 405:

{"errors":[{"code":"NotAllowedException","message":"The HTTP method is not allowed","details":null,"path":null,"userMessage":"An error occurred"}]}

Wygląda na to że nie jest obsługiwana metoda requesta HTTP. Jak zrobić żeby pobrać kategorie ? Jakiego typu requesta użyć ?

0

Dobra już wiem. Trzeba zmienić metodę POST na GET:

RestRequest1.Method := TRESTRequestMethod.rmGET;

ale teraz mam inny błąd w odpowiedzi ze statusem 401:

{"error":"unauthorized","error_description":"Full authentication is required to access this resource"}

a przecież używam prawidłowego access_tokenu więc jak naprawić ten błąd ?

0
datalux napisał(a):

ale teraz mam inny błąd w odpowiedzi ze statusem 401:

{"error":"unauthorized","error_description":"Full authentication is required to access this resource"}

a przecież używam prawidłowego access_tokenu więc jak naprawić ten błąd ?

Nie każdy z nas zna API allegro, ale każdy tutaj wiedziałbym jak sobie poradzić z takim problemem.

  • Przeczytaj wiadomość
  • Wygoogleują ją

Spróbuj wpisać w google.com:

allegro "Full authentication is required to access this resource"

I zobacz co tam znalazłeś :)

2

Już wiem. Trzeba nagłówek HTTP Authorization poprawić na:

RestRequest1.AddParameter('Authorization', 'Bearer ' +  access_token,
    TRESTRequestParameterKind.pkHTTPHEADER, [TRESTRequestParameterOption.poDoNotEncode]);

i pobierane już są kategorie główne Allegro.

1 użytkowników online, w tym zalogowanych: 0, gości: 1