Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP] Jak obecnie można pobierać zawartość aukcji Allegro?, Please enable JS and disable any ad blocker
tryme
post 7.05.2021, 18:09:47
Post #1





Grupa: Zarejestrowani
Postów: 83
Pomógł: 0
Dołączył: 5.12.2005

Ostrzeżenie: (0%)
-----


Cześć,

Jakiś czas temu pobierałem zawartość aukcji Allegro z wykorzystaniem CURL lecz od jakiegoś czasu nie mogę pobrać w żaden sposób zawartości serwisu, gdyż wyświetla mi się komunikat "Please enable JS and disable any ad blocker".

Czy jest jakiś prosty sposób, aby sobie z tym poradzić?
Go to the top of the page
+Quote Post
emillo91
post 7.05.2021, 19:15:43
Post #2





Grupa: Zarejestrowani
Postów: 129
Pomógł: 13
Dołączył: 29.03.2012

Ostrzeżenie: (0%)
-----


Najlepiej jak skorzystasz z tego API udostępnionego przez Allegro. Nie korzystałem więc nie pokieruję Cię dalej.
Go to the top of the page
+Quote Post
tryme
post 7.05.2021, 19:20:36
Post #3





Grupa: Zarejestrowani
Postów: 83
Pomógł: 0
Dołączył: 5.12.2005

Ostrzeżenie: (0%)
-----


Czytałem o tym, ale wolałbym pobrać dane tradycyjnie tym bardziej, że w najbliższym czasie dostęp do API będzie powoli ograniczany.
Go to the top of the page
+Quote Post
Tomplus
post 7.05.2021, 22:02:46
Post #4





Grupa: Zarejestrowani
Postów: 1 838
Pomógł: 226
Dołączył: 20.03.2005
Skąd: Będzin

Ostrzeżenie: (0%)
-----


@tryme
gdzie czytałeś o tym że dostęp do API będzie ograniczony?

Więcej na temat API przeczytasz na ich stronie:
https://developer.allegro.pl/
Go to the top of the page
+Quote Post
sazian
post 8.05.2021, 13:22:04
Post #5





Grupa: Zarejestrowani
Postów: 1 045
Pomógł: 141
Dołączył: 19.09.2006
Skąd: B-tów

Ostrzeżenie: (0%)
-----


Nie doczytałeś dokładnie,
stare API soap/wsdl jest wyłączane o ile jeszcze działa i jest zastępowane nowym REST API
Go to the top of the page
+Quote Post
emillo91
post 8.05.2021, 14:04:58
Post #6





Grupa: Zarejestrowani
Postów: 129
Pomógł: 13
Dołączył: 29.03.2012

Ostrzeżenie: (0%)
-----


Co do tego komunikatu błędu to gdzieś w Internecie piszą, że jest to spowodowane przez mechanizm captcha (js challenge), chroniący przed scrapingiem.
Go to the top of the page
+Quote Post
Tomplus
post 11.05.2021, 08:58:47
Post #7





Grupa: Zarejestrowani
Postów: 1 838
Pomógł: 226
Dołączył: 20.03.2005
Skąd: Będzin

Ostrzeżenie: (0%)
-----


@sazian
Tak, to już od kilku lat Allegro wycofuje, myślałem że już tego nie ma.
Dlatego myślałem że nowe API chcą wycofywać, a nie ma żadnych informacji z ich strony.
Go to the top of the page
+Quote Post
tryme
post 30.05.2021, 21:28:50
Post #8





Grupa: Zarejestrowani
Postów: 83
Pomógł: 0
Dołączył: 5.12.2005

Ostrzeżenie: (0%)
-----


Próbuję szczęścia z API REST, ale coś mi nie wychodzi closedeyes.gif Czy możecie rzucić okiem na mój kod, którym chciałbym pobrać moje oferty?

  1. <?php
  2.  
  3. function getAccessToken(): String
  4. {
  5. $authUrl = "https://allegro.pl/auth/oauth/token?grant_type=client_credentials";
  6. $clientId = "...";
  7. $clientSecret = "...";
  8.  
  9. $ch = curl_init($authUrl);
  10.  
  11. curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  12. curl_setopt($ch, CURLOPT_USERNAME, $clientId);
  13. curl_setopt($ch, CURLOPT_PASSWORD, $clientSecret);
  14. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  15.  
  16. $tokenResult = curl_exec($ch);
  17. $resultCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  18. curl_close($ch);
  19.  
  20. if ($tokenResult === false || $resultCode !== 200) {
  21. exit ("Something went wrong!");
  22. }
  23.  
  24. $tokenObject = json_decode($tokenResult);
  25.  
  26. return $tokenObject->access_token;
  27. }
  28.  
  29.  
  30. function getOffers(String $token): stdClass
  31. {
  32. $url = "https://api.allegro.pl/sale/offers";
  33.  
  34. $ch = curl_init($url);
  35.  
  36. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  37. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  38. "Authorization: Bearer $token",
  39. "Accept: application/vnd.allegro.public.v1+json"
  40. ]);
  41.  
  42. $result = curl_exec($ch);
  43. $resultCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  44. curl_close($ch);
  45.  
  46. if ($result === false || $resultCode !== 200) {
  47. exit ("Something went wrong");
  48. }
  49.  
  50. $offers = json_decode($result);
  51.  
  52. return $offers;
  53. }
  54.  
  55. function main_4()
  56. {
  57. $token = getAccessToken();
  58. var_dump(getOffers($token));
  59. }
  60.  
  61. main_4();
  62.  
  63. ?>
Go to the top of the page
+Quote Post
Pyton_000
post 31.05.2021, 14:20:47
Post #9





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

Ostrzeżenie: (0%)
-----


A błędy to mamy sobie wywróżyć czy jak?
Go to the top of the page
+Quote Post
tryme
post 31.05.2021, 20:04:47
Post #10





Grupa: Zarejestrowani
Postów: 83
Pomógł: 0
Dołączył: 5.12.2005

Ostrzeżenie: (0%)
-----


Otrzymuję następujący błąd:

Cytat
Response status code: 403 {"errors":[{"code":"AccessDenied","message":"Access is denied","details":null,"path":null,"userMessage":"Access denied. Contact the author of the application."}]}


Powiązałem aplikację z Allegro lecz nadal widzę błąd.

Ten post edytował tryme 31.05.2021, 20:05:10
Go to the top of the page
+Quote Post
gino
post 1.06.2021, 06:42:44
Post #11





Grupa: Zarejestrowani
Postów: 319
Pomógł: 52
Dołączył: 18.02.2008

Ostrzeżenie: (0%)
-----


Z tego co pamiętam (mogę się mylić bo dawno nie robiłem nic z allegro) że przez zasób sale/offers/ID_twojejoferty pobierasz konkretną ofertę jeśli jesteś jej właścicielem? Do listowania Twoich ofert nie jest przypadkiem /offers/listing? Tak mi się coś kojarzy, ale jak pisałem mogę się mylić.

Ten post edytował gino 1.06.2021, 06:42:59
Go to the top of the page
+Quote Post
Pyton_000
post 1.06.2021, 07:36:19
Post #12





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

Ostrzeżenie: (0%)
-----


Ewidentnie brak uprawnień. Możliwe że klucz API który wygenerowałeś nie ma uprawnień do listingu ofert: "allegro:api:sale:offers:read"
https://developer.allegro.pl/documentation/...hOffersUsingGET
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 27.04.2024 - 23:28